gpt4 book ai didi

c - 如何将 '//' 和 '/*...*/' 注释行视为?

转载 作者:太空宇宙 更新时间:2023-11-04 08:53:24 25 4
gpt4 key购买 nike

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

关于c - 如何将 '//' 和 '/*...*/' 注释行视为?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18699383/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com