我有一个代码段,这里我放了一个#pragma
。这会发出Wunknown-pragmas
警告:
warning: ignoring #pragma warning [-Wunknown-pragmas]
代码:
#include<iostream>
using namespace std;
int main(){
cout<<"Helloworld\n";
#ifdef __GNUC__
#pragma warning( push )
#pragma warning( disable : warning )
cout<< "I am in warning free section"<<endl;
#pragma warning( pop )
#endif
return 0;
}
如何在代码级别修复此问题?
答案 0 :(得分:0)
这不是你在GCC中使用pragma的方式。它应该更像是:
#include<iostream>
//example function that
//complains if its result is unused
__attribute__((__warn_unused_result__)) int foo() { return 42; }
using namespace std;
int main(){
cout<<"Helloworld\n";
foo();
#ifdef __GNUC__
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-result"
foo(); //no complaints here
cout<< "I am in warning free section"<< endl;
#pragma GCC diagnostic pop
#endif
return 0;
}
有关详细信息,请参阅gcc manual。