[英]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");
*/
这是在创造错误。
您期望的是要嵌套的多行注释。
直接从标准C11
引用,第6.4.9章,
除了字符常量,字符串文字或注释之外,字符
/*
引入注释。 检查此类注释的内容仅用于标识多字节字符并查找终止它的字符*/
。 83)
和脚注,
83) 因此,
/* ... */
comments不会嵌套。
作为解决方法,您可以使用条件编译块作为
#if 0
.
.
.
.
#endif
将整个块注释掉 。
你能做的是
#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
之间的所有内容都将被编译器忽略,就像它是注释一样。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.