Can // style comments be continued to the next line by using a back slash, like multi-line macros? E.g.
// here is a comment \
and this is more comments \
const char* x = "hello"; // this line of "code" is actually still a comment
int x = 5; // and now an actual line of code
Yes. Lines terminated by a
\are spliced together with the next line very early in the process of translation. It happens at phase 2 of translation, before comment removal and before preprocessor has a chance to do its work.Comment recognition and removal takes place at phase 3. For this reason you can turn a
//comment into what looks like a multi-line comment by using the\. This usually fools most syntax-highlighting source code parsers.Preprocessor works at phase 4.
This all means that you can “multiline” virtually anything using the
\, including comments and preprocessor directivesP.S. Please note that the terminating
\does not introduce any whitespace into the spliced line. This should be taking onto account when writing multi-line comments using the\feature. For example, the following commentstands for the single word “together” and not for three separate words “to get her”. Obviously, incorrect use of
\in comments might drastically obfuscate and even distort their intended meaning.