Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

TreborZehn

macro to disable unused parameters warning?

This topic is 5336 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I''m programming in Windows and as you may know with WinMain function is required to take a specific set of parameters and a couple of them are rarely used. The problem is I get a "unused parameters warning" whenever I compile my code. I''m a bit of a purist when it comes to warnings. I never disable them with a compiler switch because there have been many times when they''ve helped me catch bugs, and write cleaner/more efficient code. Therefore I don''t want to disable the "unused parameters" warning all together. Is there a macro I can use (ANSI C would be best but even something included via "windows.h" would be OK) that I can wrap around parameter names that I don''t want to be warned about. For example...
int MyFunc(int param1, int param2)
{
    TOUCH_PARAMETER(param2);
    return (param1 + 1);
}
 
Any advice would be appreciated. Thanks "Good code will come and go, but bad code sticks around."

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
Don''t name the parameter and you won''t get a warning:


int whatever(int param1, int, int param3)
{
use(param1, param3);
return 0;
}


This does not produce any warnings.

Share this post


Link to post
Share on other sites
How about this?


#define UNUSED( PARAMETER )

int MyFunc(int param1, int UNUSED( param2 ) )
{
return (param1 + 1);
}

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
You might want to look at UNREFERENCED_PARAMETER (include <windows.h>

Share this post


Link to post
Share on other sites
Using MSVC, the warning you will get for an unreferenced paramter is 4100. Temporarily turning off this warning (or any warning) is simple:


#pragma warning(disable: 4100) // turn off warning 4100

int MyFunc(int param1, int param2)
{
return (param1 + 1);
}
#pragma warning(default: 4100) // restore 4100''s warning


Share this post


Link to post
Share on other sites
I just don''t label the parameter like first reply suggested. If you want to keep a little documentation though, I tend to give the variable a relevent label and comment it out so you know what it is that is being ignored. There really isn''t a need to use macros and using pragma is compiler dependent.

Share this post


Link to post
Share on other sites
Thanks all for your fast response.
I was fishing for the UNREFERENCED_PARAMETER aluded to by the anonymous poster. I had seen it somewhere in an example but couldn''t remember enough of the name to find the actual macro name via Google.

It''s also interesting to me that leaving a parameter unnamed doesn''t give the warning... not sure if I like that idea. I mean I''m not doubting that it works I''m just thinking if it''s a good thing from a Programming Practices perspecitive. If I did utilize that quirk I think I would go the route of Willm.

Anyway thanks for all the info.

"Good code will come and go, but bad code sticks around."

Share this post


Link to post
Share on other sites
quote:
Original post by TreborZehn
Thanks all for your fast response.
I was fishing for the UNREFERENCED_PARAMETER aluded to by the anonymous poster. I had seen it somewhere in an example but couldn''t remember enough of the name to find the actual macro name via Google.

It''s also interesting to me that leaving a parameter unnamed doesn''t give the warning... not sure if I like that idea. I mean I''m not doubting that it works I''m just thinking if it''s a good thing from a Programming Practices perspecitive. If I did utilize that quirk I think I would go the route of Willm.



It isn''t a quirk, it''s a feature.

Seriously, that''s one of its legitamate uses. I''ve seen companies that use macros to signal unused variables, other comment out the label. It''s doesn''t make that much difference, although using the windows.h macro will obviously give you a ''dependency'' to Windows which should be avoided.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
quote:
Original post by seanw
...using the windows.h macro will obviously give you a ''dependency'' to Windows which should be avoided.
About this ''obvious dependency'' to Windows.... Is it difficult to define UNREFERENCED_PARAMETER your platform or what are you saying? Then maybe you should consider a platform change.

Share this post


Link to post
Share on other sites
quote:
Original post by Anonymous Poster
About this ''obvious dependency'' to Windows.... Is it difficult to define UNREFERENCED_PARAMETER your platform or what are you saying? Then maybe you should consider a platform change.


No, I just meant you''d be better creating your own macro and placing it in your own header and including that, instead of using the one in windows.h. If you try to compile on a non-windows platform, that macro isn''t going to be available to you. It''s not a big deal, just that you shouldn''t create needless dependencies and this one can easily be avoided. Just good programming practice.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!