Sign in to follow this  
1st_maza

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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
Share on other sites
Quote:
Original post by 1st_maza
Why 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 this post


Link to post
Share on other sites
Quote:
Original post by 1st_maza
Why 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 this post


Link to post
Share on other sites
Quote:
Original post by 1st_maza
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


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 this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this