Reputation: 362
I'm working in Eclipse-CDT and I have the following #define statement:
#define IS_ARGUMENT_NULL(arg) if (NULL == arg) {fprintf(stderr, "%s is NULL", #arg); bool isNull = true;}
The line is too long for me (I need to keep up to max 80 characters per line) and I was wondering how could I go down a line with the code to compile ok. I tried pressing enter and getting
#define IS_ARGUMENT_NULL(arg) if (NULL == arg) {fprintf(stderr, "%s is NULL", #arg);
bool isNull = true;}
but it won't compile. Says "expected identifier or ‘(’ before ‘}’ token" on the second line
Upvotes: 0
Views: 246
Reputation: 14044
Backslash (\
) is the line continuation character.
#define IS_ARGUMENT_NULL(arg) \
if (NULL == arg) { \
fprintf(stderr, "%s is NULL", #arg); \
bool isNull = true; \
}
From the gcc manual:
The macro's body ends at the end of the ‘#define’ line. You may continue the definition onto multiple lines, if necessary, using backslash-newline. When the macro is expanded, however, it will all come out on one line.
Upvotes: 1