2016-12-14 60 views
3

如何忽略多行注释符号另一个多行注释?C语言编程 - 多行注释

说我想要把整个代码中的注释,这样我可以在我的代码

/* 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"); 

*/ 

这是创建错误。

+2

大多数现代IDE都有一些工具可以帮助您进行块评论,只需单击一下鼠标即可。正如下面的回答评论所说,你可能不能这样做。 –

+0

另外,这是不使用多行注释的好理由。 –

回答

7

预计这里是多行注释为嵌套

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

除了一个字符内是恒定的,字符串文字或注释,字符/* 介绍评论。这种评论的内容仅用于识别 多字节字符并查找终止它的字符*/83)

和脚注,

83)因此,/* ... */注释不嵌套。

作为一种变通方法,您可以使用条件编译块作为

#if 0 
. 
. 
. 
. 
#endif 

有一个整体的块注释掉

+0

@iharob对,这就是为什么我提到以斜体__提到的原因。 :) –

+1

谢谢:) .. StackOverflow增加了我学习的东西。很高兴它..我从来没有使用#如果0 ..... #endif。所以非常感谢你:) –

2

你可以做的是

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

要注释掉包含本身的意见一些代码,我想。

可以使用conditionnal编译此:

#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 

一切和#endif之间#if 0将被编译器忽略,就好像它是一个注释。