Why do multi-line macros have backslashes at the end of each line?
It's a line continuation character.
There should be nothing else after it (aside from an end of line character), including white space.
It's particularly useful for macros as it adds clarity.
(Very, very occasionally - especially in old code - you'll see the trigraph sequence ??/
in place of \
. These days though it's more of an interviewers' trick question.)
The slashes are used to make the following end of line a non-linebreak for the preprocessor. A #define
has to be exactly one line for the preprocessor. To augment readability you can use the backslashes before the end of lines. The preprocessor will first erase any linebreaks preceded by a backslash and only after that parse the #define
. So while you see multiple lines, the PP sees only one.
It is so called continued line. It means that your line is continued in line that follows. It is simply sometimes easier to read stuff if written this way.
BTW - continued lines are 'glued' at preprocessor pass.
Read here about step #3: gcc docs
Excerpt:
/\
*
*/ # /*
*/ defi\
ne FO\
O 10\
20
is equivalent to:
#define FOO 1020
It is noteworthy to say that continued lines do not have to be used within preprocessor macros. It is perfectly legal top write this:
f\
lo\
at f = 5.0;
which is the same as:
float f = 5.0;