1
votes

I thought whitespace effectively did not matter in C. Is this different for the preprocessor? Why do we need to use " \ " when creating multiline macros?

1
The preprocessor cannot know where your macro ends if it occupies more than one line (there is no #end** for a #define: it's a one-liner). The \ shows that is continues on the next line.Weather Vane

1 Answers

2
votes

Preprocessor directives are terminated by a newline character, so in that context newlines are distinguished from other whitespace.

Newlines are also distinguished inside // comments and string literals. In both cases, line-splicing can be used to extend the lexeme, although it's not considered good style.

Equally, you can extend preprocessor lines using multiline comments, because comments are replaced with a space before preprocessing directives are recognised. That probably would also be discouraged by style guides if they thought of it.