簡體   English   中英

GNU c++ 編譯器選項來標記 if (a = b)

[英]GNU c++ compiler option to flag if (a = b)

今天早上腦筋急轉彎。 不記得要標記的 GNU 編譯器選項

if (a = b) 

作為警告/錯誤,因為它是一個任務,而不是一個條件。

最簡單的方法是啟用所有警告並查看報告的內容:

int main(int argc, char **argv){
    if(argc=0) ;
}

-Wall編譯

你會得到警告:

<source>: In function 'int main(int, char**)':

<source>:3:12: warning: suggest parentheses around assignment used as truth value [-Wparentheses]

    3 |     if(argc=0) ;

      |        ~~~~^~

Compiler returned: 0

所以選項是: -Wparentheses

https://godbolt.org/z/6ac1zG

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM