Backslash in the end of comment lines in C/C++
Asked Answered
H

10

18

Does your editor/ide highlight that a++; in this C/C++ code as part of a comment?

int a=1;
//some comment \
a++;
printf("%d\n",a);

And what about this?

int a=1;
//some comment ??/
a++;
printf("%d\n",a);
Heiress answered 5/3, 2010 at 2:56 Comment(8)
BTW, should it be a comment? I'm confused.Kick
I think this should be community wiki.Keening
I once asked "what's wrong" sort of question as a "c++ quiz" using this weirdness on stackoverflow (of course, replacing "\" by the trigraph "// what the heck ??/"). And the question was downvoted heavily. People didn't like how they were fooled :)Keening
@Javier:yes -- line splicing happens in phase 2 of translation, replacement of a comment by a space happens in phase 3.Achromaticity
The lesson, Don't have a backslash in C99 one-lined comments, please. :)Utu
The trigraph question is tricky, personally I compile with trigraphs disabled so I am perfectly fine with my IDE not recognizing them.Markowitz
I'm confused, can someone explain? are those a++; supposed to be part of the comment?Chlorophyll
I’m voting to close this question because it's asking whether a particular feature is implemented in an arbitrary IDE. This is a "list-style" question that isn't useful to readers.Outlander
H
1

emacs 22.3.1: No to both, sadly

Headachy answered 5/3, 2010 at 2:56 Comment(2)
The same for my Emacs 23.1.1 Should we file a bug report?Postprandial
<flamebait>That's why you have to switch to vim</flamebait>Telefilm
P
2

vim 7.2 sees it as a comment, and gcc 3.4.3 compiles it as a comment.

Premiership answered 5/3, 2010 at 2:56 Comment(1)
The install of vim I have (7.2, Ubuntu 10.04) sees the first one correctly, but misses on the trigraph.Shotwell
C
2

VC6, Visual Studio 2003, 2005, 2008, 2010 all do.

Caviness answered 5/3, 2010 at 3:12 Comment(0)
G
2

Slickedit - yes

KDevelop - yes

QT Creator - No

CodeBlocks - No

Gingersnap answered 5/3, 2010 at 3:17 Comment(0)
H
1

emacs 22.3.1: No to both, sadly

Headachy answered 5/3, 2010 at 2:56 Comment(2)
The same for my Emacs 23.1.1 Should we file a bug report?Postprandial
<flamebait>That's why you have to switch to vim</flamebait>Telefilm
K
1

Kate (3.4) only highlights the first test, fails hilighting the second test

// hello folks \
int a = 0;

// hello folks ??/
int a = 0;
Keening answered 5/3, 2010 at 2:56 Comment(0)
L
1

Yes, TextMate does it.

Lancewood answered 5/3, 2010 at 2:58 Comment(0)
S
0

Good question! I was going to ask a question about this until I found this one.

The Visual-DSP++ IDE from Analog Devices does not highlight either comment when writing in assembly or C. For example:

r1 = dm(pPointer1);      // Store pointer to r0\
r0 = lshift r1 by -16;   // Not highlighted as a comment but DOES NOT EXECUTE.
dm(i0,m1) = r0;
dm(i0,m1) = r1;
See answered 5/3, 2010 at 2:56 Comment(0)
J
0

Xcode sees the first as a comment, the second not.

Jared answered 5/3, 2010 at 2:56 Comment(0)
L
0

XCode and CodeWarrior handle it properly. (But not the trigraph, lol.)

Leone answered 5/3, 2010 at 2:56 Comment(0)
P
0

From http://forums.topcoder.com/?module=Thread&threadID=666932

Quick note on which popular editors show this as a comment : vim - yes emacs - no :) kate - no gedit - yes netbeans - yes kwrite - yes

Postprandial answered 5/3, 2010 at 2:58 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.