Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to deal with Warning C4100 in Visual Studio 2008

For some reason my Visual Studio 2008 began to show warnings for code like: "int main( int argc, char **argv)", which is really annoying.

The detailed warning ouputs are (you can ignore the line numbers):
1>.\main.cpp(86) : warning C4100: 'argv' : unreferenced formal parameter
1>.\main.cpp(86) : warning C4100: 'argc' : unreferenced formal parameter

I wonder if there are settings in Visual Studio 2008 that have been accidentally changed. Or how should I deal with this warning?

like image 289
Jimmie Avatar asked Mar 25 '10 22:03

Jimmie


People also ask

How do I enable warnings in Visual Studio?

If you want to turn it on (or off) in the project setting, you have to go to: Configuration Properties -> C/C++ -> Command Line and then under Additional Options you can enter: /w3#### to set your warning to level 3, and thus enable it; or you can enter /wd#### to disable a warning.

How do I stop warnings in CPP?

To disable a set of warnings for a given piece of code, you have to start with a “push” pre-processor instruction, then with a disabling instruction for each of the warning you want to suppress, and finish with a “pop” pre-processor instruction.


2 Answers

If the parameters are unreferenced, you can leave them unnamed:

int main(int, char**)
{
}

instead of

int main(int argc, char** argv)
{
}

If you really want just to suppress the warning, you can do so using the /wd4100 command line option to the compiler or using #pragma warning(disable: 4100) in your code.

This is a level 4 warning; if you compile at a lower warning level, you won't get this warning. The warning level is set in the project properties (right-click project, select Properties; on the Configuration Properties -> C++ -> General, set "Warning Level").

like image 77
James McNellis Avatar answered Oct 01 '22 09:10

James McNellis


If you're not using the command line parameters then the other standard signature for main is:

int main();
like image 36
CB Bailey Avatar answered Oct 01 '22 11:10

CB Bailey