Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
419 views
in Technique[技术] by (71.8m points)

C++ Multi-line comments using backslash

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
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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 directives

#
d
e
f
i
n
e 
ABC 
int i

int main() {
A
B
C = 5;
}

P.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 comment

// to
get
her

stands 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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...