#pragma GCC diagnostic ignored "-Wformat"的使用
在GCC下,#pragma GCC diagnostic ignored用于表示關閉診斷警告,忽略診斷問題,
格式:
#pragma GCC diagnostic ignored "-Wformat"
示例程式如下:
#include <stdio.h>
/************************************************************************/
int test1(void)
{
return;
}
//關閉警告,診斷忽略該函式沒有回傳值
#pragma GCC diagnostic ignored "-Wreturn-type"
int test2(void)
{
return;
}
/************************************************************************/
int main(int argc, char* argv[])
{
test1();
test2();
return 0;
}
在gcc下編譯
gcc -o test test.c -Wall
函式test1會提示警告不帶回傳值,而函式test2沒有警告,
test.c: 在函式‘test1’中:
test.c:6:5: 警告: 在有回傳值的的函式中,‘return’不帶回傳值 [-Wreturn-type]
如果屏蔽掉
//#pragma GCC diagnostic ignored "-Wreturn-type"
重新編譯,則兩個函式都是提示警告
test.c: 在函式‘test1’中:
test.c:6:5: 警告: 在有回傳值的的函式中,‘return’不帶回傳值 [-Wreturn-type]
test.c: 在函式‘test2’中:
test.c:14:5: 警告: 在有回傳值的的函式中,‘return’不帶回傳值 [-Wreturn-type]
[參考資料]
GCC, the GNU Compiler Collection
GCC, Diagnostic Pragmas
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/142096.html
標籤:AI
上一篇:Faceshift Studio
