我对C语言的评论有疑问.当我们写作例如
//this is the first step
Run Code Online (Sandbox Code Playgroud)
这意味着评论.
但是当我们写作时
//this is the first step;
Run Code Online (Sandbox Code Playgroud)
这是否也意味着评论?我的意思是当我们在双斜线后添加分号时,这是否意味着评论或程序的主要部分?
双斜线后的所有内容都是评论.
这包括分号,运算符,预处理程序指令,关键字甚至猫.
编辑:
我发现有趣的东西:
//comment \
also part of the comment\
this too part of the comment
Run Code Online (Sandbox Code Playgroud)
我想反斜杠实际上是解析的.这是线条延续字符.值得一提的是我想.
我想SO解析器不识别该字符,但确实存在 - 至少在MSVC中存在.不确定它是否属于标准的一部分.
编辑2:
正如@vsz指出的那样,即使在评论中也会解析三字符:
/*
??/ is translated to \
the following is not safe:
*/
//do we really need this??/
i++;
Run Code Online (Sandbox Code Playgroud)
之前的代码i++;将不会被执行,因为它??/被替换为\,因此i++;成为注释的一部分.