C 编程 - 多行注释

C Programming - Multi-line comments

如何忽略里面另一个多行注释的多行注释符号?

假设我想将整个代码放在注释中,以便我可以测试我代码中的其他内容

/* This is my first comment */
printf("\n This is my first print command");

/* This is my second comment */
printf("\n This is my second print command");

如果我这样做

/* 

/* This is my first comment */
printf("\n This is my first print command");

/* This is my second comment */
printf("\n This is my second print command");

*/

这是创建错误。

你能做的是

#if 0
/Code that needs to be commented/
#endif

我想你想注释掉一些本身包含注释的代码。

您可以为此使用条件编译:

#if 0
/* This is my first comment */
printf("\n This is my first print command");

/* This is my second comment */
printf("\n This is my second print command");
#endif

#if 0#endif 之间的所有内容都将被编译器忽略,就像它是注释一样。

期待的是嵌套的多行注释。

直接引用标准 C11,章节 §6.4.9,

Except within a character constant, a string literal, or a comment, the characters /* introduce a comment. The contents of such a comment are examined only to identify multibyte characters and to find the characters */ that terminate it. 83)

和脚注,

83 ) Thus, /* ... */ comments do not nest.

作为解决方法,您可以使用条件编译块作为

#if 0
.
.
.
.
#endif 

将整个块注释掉