在VC++中编译以下程序,会产生3个告警warnings
1
#include
"
stdio.h
"
2
3 int main()
4 {
5 int x, y, z;
6 y = x;
7 }
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 }
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)