2016-12-14 59 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將被編譯器忽略,就好像它是一個註釋。