warning C4100

Recommended Posts

Felt like it was a good thing to activate warning level 4 in Visual Studio and this is what happend.. Why am I getting these warnings: main.cpp(16) : warning C4100: 'nCmdShow' : unreferenced formal parameter main.cpp(16) : warning C4100: 'hPrevInstance' : unreferenced formal parameter Line 16, that is being "warned" about: int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow ) edit: Never gotten this warning either but I would like to understand why: main.cpp(50) : warning C4189: 'windowRect' : local variable is initialized but not referenced Line 50, that is being "warned" about: else if( ... ) // This one is also located right after RegisterClassEx( &wc ).. { RECT windowRect = { 0, 0, 1280, 960 }; biggest = true; } also have RECT windowRect = { 0 }; in the beginning of WinMain

Share on other sites
You are naming parameters for a function that you never use. For functions like WinMain this is pretty harmless, but to get rid of the warning you can change the parameter list like so:

int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE, LPSTR lpCmdLine, int )

Share on other sites
Why is it whining about that the thing is not being used? Should I just go back to warning level 3?

Share on other sites
You can also just do:
(void)theUnusedArg;

to get rid of the warning.

The C4189 warning means that you've simply made a local a variable but you're not using anywhere. Just get rid of the variable and the warning should go away.

Share on other sites
Quote:
 Original post by 1st_mazaWhy is it whining about that the thing is not being used? Should I just go back to warning level 3?

Why have it when you don't use it? It's worth having taken a look at, hence the warning.

As others have pointed out, if it actually makes sense to have an parameter that is not used, there are ways to express that.

Share on other sites
Quote:
 Original post by 1st_mazaWhy is it whining about that the thing is not being used?
Because you may have made a function that recieves parameters and you accidentally forget to use them. But the truth is, in the majority of the cases you do it in purpose... This is true for functions like WinMain and callback functions, which have generic prototypes.

There are tricks to get around that if you don't want to disable that specific warning.

[Edited by - Sik_the_hedgehog on March 14, 2009 8:25:55 PM]

Share on other sites
Quote:
 Original post by 1st_mazaNever gotten this warning either but I would like to understand why:main.cpp(50) : warning C4189: 'windowRect' : local variable is initialized but not referencedLine 50, that is being "warned" about:else if( ... ) // This one is also located right after RegisterClassEx( &wc )..{RECT windowRect = { 0, 0, 1280, 960 };biggest = true;}also haveRECT windowRect = { 0 };in the beginning of WinMain

This might actually be an error in your program. It seems as though you want to change the data in your windowRect you declare in the beginning of WinMain, but you do not, you create a new RECT with the same name and give it different values, but it then seizes to exist right away and the original one is never altered.
You shouldn't have 'RECT ' there before windowRect, since then it declares a new variable. Instead use something like SetRect(&windowRect, 0, 0, 1280, 960).

Share on other sites
This is precisely why such warnings exist. Nice catch!

~Jonathan

Create an account

Register a new account

• Forum Statistics

• Total Topics
627737
• Total Posts
2978873

• 10
• 10
• 21
• 14
• 12