0

I need a special include file (in essence a very log list of names) included in the middle of my code (and I cannot make a list a part of any structure). It works but it looks ugly:

    <code>;
#include <big_list.inc>
    <more-code>;

Is it possible to define some macro to include this file, I feel that this would look better.

#define BIG_LIST_INC() ...

    <code>;
    BIT_LIST_INC();
    <more_code>;
uuu777
  • 765
  • 4
  • 21

2 Answers2

2

Change the contents of your include file to :

#define BIG_LIST_INC ...

where ... is the current content of the file (if it spans multiple lines, don't forget to end lines with \).

Then include the file at the top of your source file, and the big list can be inserted in the code using BIG_LIST_INC :

#include "big_list.h"

// <code>
BIG_LIST_INC
// <more_code>
Sander De Dycker
  • 16,053
  • 1
  • 35
  • 40
  • It seems to me that in this case all big list definitions will be on one line after preprocessor run, the list is big I am afraid to blow limit on the line length. It will be perfect solution if list items will be placed on separate line – uuu777 Apr 20 '17 at 13:41
  • @zzz777 : as mentioned in the answer, macro's can span multiple lines with the use of the \ line break character – Sander De Dycker Apr 20 '17 at 13:50
  • As far as I understand after the preprocessing the whole list will be on one line. – uuu777 Apr 21 '17 at 01:08
  • @zzz777 : ah, you're talking about the logical source line limit. Unless you actually run into an issue with that, I wouldn't worry about it. [gcc eg. imposes no such limit](https://gcc.gnu.org/onlinedocs/cpp/Implementation-limits.html), and I'm sure most popular compilers don't either (check your compiler documentation to confirm). – Sander De Dycker Apr 21 '17 at 08:56
0

It might perhaps be an option to replace this with 3 include directives

#include "pre_macro_stuff.h"  
#include <big_list.inc>  
#include "post_macro_stuff.h"

Where pre_macro_stuff.h and post_macro_stuff.h contains the macros.

Lundin
  • 195,001
  • 40
  • 254
  • 396