Virtual C++ ignore warnings

Virtual C++ ignore warnings,第1张

if we enable "-Wall -Werror" on Virtual C++, Virtual C++ will report all warnings and take it as error.

But you want to ignore some warnings in some cases. So we need to find a way to ignore warnings. Virtual C++ provide '#pragma warning( xxx)' to do it.

Here is the example:

#pragma warning( push )
#pragma warning( disable : 4100 )
int main(int argc, char** argv)
{
#pragma warning( pop )

#pragma warning( push )
#pragma warning( disable : 4101 )
	int a;
#pragma warning( pop )
	printf("hello world\n");
	return 0;
}

In this code, we ignore two warnings. first is 4100, second is 4101.

4100 is parameter is not used.

4101 is variable is not used.

For GCC, we use __attribute__((unused)) for both unused parameters and variables.

欢迎分享,转载请注明来源:内存溢出

原文地址:https://www.54852.com/langs/634840.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-04-16
下一篇2022-04-16

发表评论

登录后才能评论

评论列表(0条)

    保存