我有一个代码片段,在这里我放了一个#pragma
.这给出了Wunknown-pragmas
警告:
warning: ignoring #pragma warning [-Wunknown-pragmas]
法典:
#include<iostream>
using namespace std;
int main(){
cout<<"Helloworldn";
#ifdef __GNUC__
#pragma warning( push )
#pragma warning( disable : warning )
cout<< "I am in warning free section"<<endl;
#pragma warning( pop )
#endif
return 0;
}
如何在代码级别解决此问题?
这不是你在GCC中使用编译指示的方式。它应该更像:
#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<<"Helloworldn";
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 手册。