macro to disable unused parameters warning?

Started by
13 comments, last by TreborZehn 20 years ago
quote:Original post by TreborZehn
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.

Suppose you''re implementing an interface defined by someone else. Then you might not want to utilize all parameters you get in a function call (while somone else, in another implementation of the same interface, could need all parameters). Therefore it''s really necessary not being forced to use all parameters, and it''s a really valid and useful thing to do. So not having a warning in that case is a good thing.

A static code analyzer, such as LINT, can probably be configured to issue warnings in this case.
Advertisement
quote:Original post by TreborZehn
It''s also interesting to me that leaving a parameter unnamed doesn''t give the warning... not sure if I like that idea.


Fior MSVC compilers, the default warning level is 3, which doesn''t included warnings about unreferenced parameters and a whole whack of other minor things. I always turn my warning level up to 4 (the highest). Well, that''s not exactly true I guess: sometimes certain 3rd party API''s spew mountains of warnings on level 4, so then I revert back to level 3.

Brianmiserere nostri Domine miserere nostri
quote:Original post by BriTeg
Fior MSVC compilers, the default warning level is 3, which doesn''t included warnings about unreferenced parameters and a whole whack of other minor things. I always turn my warning level up to 4 (the highest). Well, that''s not exactly true I guess: sometimes certain 3rd party API''s spew mountains of warnings on level 4, so then I revert back to level 3.


I like to keep the warning level high too, just to stop obscure bugs creeping in. Most compilers have options to set the warning level to be less strict for different files (ie you can set MSVC to less strict warnings only for the 3rd party API''s that have warnings).

In case you''re wondering, there''s no "magic" behind the UNREFERENCED_PARAMETER macro. Here''s the defintion from winnt.h (which gets included via windows.h, so you don''t need to add any extra includes):

#if ! (defined(lint) || defined(_lint))#define UNREFERENCED_PARAMETER(P)          (P)#define DBG_UNREFERENCED_PARAMETER(P)      (P)#define DBG_UNREFERENCED_LOCAL_VARIABLE(V) (V)#else // lint or _lint// Note: lint -e530 says don''t complain about uninitialized variables for// this.  line +e530 turns that checking back on.  Error 527 has to do with// unreachable code.#define UNREFERENCED_PARAMETER(P)          \    /*lint -e527 -e530 */ \    { \        (P) = (P); \    } \    /*lint +e527 +e530 */#define DBG_UNREFERENCED_PARAMETER(P)      \    /*lint -e527 -e530 */ \    { \        (P) = (P); \    } \    /*lint +e527 +e530 */#define DBG_UNREFERENCED_LOCAL_VARIABLE(V) \    /*lint -e527 -e530 */ \    { \        (V) = (V); \    } \    /*lint +e527 +e530 */#endif // lint or _lint


So basically, it''s just doing an assignment statement which the compiler should optimize away.
quote:
In case you''re wondering, there''s no "magic" behind the UNREFERENCED_PARAMETER macro. Here''s the defintion from winnt.h (which gets included via windows.h, so you don''t need to add any extra includes):

...

So basically, it''s just doing an assignment statement which the compiler should optimize away.

Wow, that''s odd; I thought the macro would be defined more like this:
#define UNREFERENCED_PARAMETER(p) /*does nothing*/ 

I usually just leave out the name if I don''t use it.

This topic is closed to new replies.

Advertisement