C 编程 - 多行注释

标签 c syntax comments line

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

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

/* 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,

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.

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

#if 0
.
.
.
.
#endif 

将整个 block 注释掉

关于C 编程 - 多行注释,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41138195/

相关文章:

c - 将 argc 和 argv 传递给 c 中的线程

c - C 库最初如何读取语言环境文件

C: 将 int 转换为 size_t

Javascript += 等效?

c - 关于函数声明的问题

ruby - Ruby 中的多行注释?

c# - 是否可以在 C# 文档注释中使用 < & > 作为泛型示例?

c# - 如何通过变量查找分配的内存?

java - if(something || someElse || someElse2 || someElse3 ...) 的替代方法

c - 扫描代码注释并转换为标准格式的工具