ABanerjee
ABanerjee

Reputation: 195

How are '//' and '/*...*/' comment lines taken as?

I was making a C program that removes comments from a program... so i was wondering if '//', '/*' and '*\' taken as 1 character, (like \t, \n \b) or are they taken as 2 characters ( literally, i.e /(1)/(2) ) Thanks :)

Upvotes: 0

Views: 154

Answers (1)

Jonathan Leffler
Jonathan Leffler

Reputation: 753625

Multi-character character constants such as '//' are valid but have implementation-defined values.

Note that stripping C comments is hard. This is part of the torture test I use on my C comment stripper:

"And escaped double quotes at the end of a string\""

aa '\\
n' OK
aa "\""
aa "\
\n"

This is followed by C++/C99 comment number 1.
// C++/C99 comment with \
continuation character \
on three source lines (this should not be seen with the -C flag)
The C++/C99 comment number 1 has finished.

This is followed by C++/C99 comment number 2.
/\
/\
C++/C99 comment (this should not be seen with the -C flag)
The C++/C99 comment number 2 has finished.

This is followed by regular C comment number 1.
/\
*\
Regular
comment
*\
/
The regular C comment number 1 has finished.

/\
\/ This is not a C++/C99 comment!

This is followed by C++/C99 comment number 3.
/\
\
\
/ But this is a C++/C99 comment!
The C++/C99 comment number 3 has finished.

Upvotes: 2

Related Questions