屏蔽编译告警 #pragma warning(disable:4508 4101 4700)

本文介绍如何在VC++中通过使用#pragma指令来禁用特定的编译警告,包括函数未返回值、未引用局部变量及未初始化局部变量使用的警告。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 

在VC++中编译以下程序,会产生3个告警warnings

 

1 #include "stdio.h"
2 
3 int main()
4 {
5     int x, y, z;
6     y = x;
7 }

 

--------------------Configuration: foo1 - Win32 Debug--------------------
Compiling...
entry.cpp
f:\foo\foo1\entry.cpp(7) : warning C4508: 'main' : function should return a value; 'void' return type assumed
f:\foo\foo1\entry.cpp(5) : warning C4101: 'z' : unreferenced local variable
f:\foo\foo1\entry.cpp(6) : warning C4700: local variable 'x' used without having been initialized
Linking...

foo1.exe - 0 error(s), 3 warning(s)

 

如果不希望这些告警出现,可以使用#pragma指令:

 

1 #include "stdio.h"
2 
3 #pragma warning(disable:4508 4101 4700)
4 
5 int main()
6 {
7     int x, y, z;
8     y = x;
9 }

 

编译结果中就不会有告警了:

--------------------Configuration: foo1 - Win32 Debug--------------------
Compiling...
entry.cpp
Linking...

foo1.exe - 0 error(s), 0 warning(s)

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值