0

我正在制作一个从程序中删除注释的 C 程序...所以我想知道是否'//','/*'并被'*\'视为 1 个字符(如\t, \n \b)或者它们是否被视为 2 个字符(字面意思,即/(1)/(2))谢谢 :)

4

1 回答 1

2

多字符字符常量,例如'//'有效但具有实现定义的值。

请注意,剥离 C 注释很难。这是我在 C 注释剥离器上使用的酷刑测试的一部分:

"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.
于 2013-09-09T13:39:59.403 回答