I know that executing Java code in comments with certain Unicode characters is allowed. Please see this question for further clarification Executing Java code in comments. So was just curious to know if C++ has such features?
Asked
Active
Viewed 1,111 times
1
-
1What do you mean by "executing C++ code in comments"? – Some programmer dude Jun 23 '15 at 07:14
-
Please see the link provided in the question description @JoachimPileborg – spharish Jun 23 '15 at 07:15
-
3That is not "executing C++ code in comments", it is "I see a single line in the editor but the compiler interprets it as two, because of the unicode character for new line" – SJuan76 Jun 23 '15 at 07:21
-
Now that you've got the answer for C++, you can apply a similar, specification-based analysis for Java. But the translation steps are different. You'll find that the code in question is not part of the comment at all. So, the wording of the question doesn't actually make any sense. – Tom Blodget Jun 24 '15 at 02:56
1 Answers
10
If I read this translation phase reference correctly, then the sequence
// \u000d some code here
is mapped in phase 1 to itself, i.e. the parser does not translate or expand \u000d
. Instead the translation of such sequences happens in phase 5, which is after the comments are replaced by a space in phase 3.
So to answer your question: C++ does not "execute" (or parse) code in comments, not even with a Unicode newline in it.

Some programmer dude
- 400,186
- 35
- 402
- 621