backslash+newline

In C++ you can put a \<newline> anywhere in the source and it will be ignored
eg:
1
2
3
std::co\
ut << "hello \
world";

This is usually found in macros:
1
2
#define debug(s, t) printf("x" # s "= %d, x" # t "= %s", \
                               x ## s, x ## t) 
This last piece of code is from the ISO document itself.

The question is, where does the standard say that this is valid?
I couldn't find it anywhere.

Moreover, the definition of a preprocessing directive is the following:
§16 [cpp]
A preprocessing directive consists of a sequence of preprocessing tokens. The first token in the sequence is a # preprocessing token that is either the first character in the source file (optionally after white space containing no new-line characters) or that follows white space containing at least one new-line character. The last token in the sequence is the first new-line character that follows the first token in the sequence.



I don't remember where, exactly, you can read about it, but it happens in the file reading before the preprocessor gets it. (Or, at least, it used to, if it doesn't for your particular compiler, but it is always treated that way.)

Hence, it isn't in the C or C++ standard, but probably in the K&R cc documentation or something like that.
Thanks K&R does mention it as 'line splicing',
Now I've found it in the C++ standard as well ( §2.1.2 [lex.phases] )
Each instance of a new-line character and an immediately preceding backslash character is deleted,
splicing physical source lines to form logical source lines.

For some reason it doesn't appear in the ISO document index


There is a bit of clash in my head between C and C++, but I believe in some of those languages the escaped newline is converted into white space instead of simply skipped. There is no mention of that in the C++ standard, so probably it was C.
Both in C and C++ it's simply ignored
Topic archived. No new replies allowed.