Menu
Forums
New posts
Search forums
Members
Current visitors
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Forums
Archive
Archive
C Programming
Table of "safe" methods to suppress "unused parameter" warnings?
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
[QUOTE="mathog, post: 5151523"] Sometimes the same parameter list must be passed to a lot of different functions, and some of those will not use all of the parameters, resulting in some compilers emitting "unused parameter" warnings. Here are all of the methods I have found so far for suppressing these: This first set of UNUSED's are applied where the parameters are declared in the function, as in int function( UNUSED(x)){ #ifdef UNUSED #elif defined(__GNUC__) # define UNUSED(x) UNUSED_ ## x __attribute__((unused)) #elif defined(__LCLINT__) # define UNUSED(x) /*@unused@*/ x #else # define UNUSED(x) x #endif The main problem with these is that the method only works for compilers and tools that define a way to ignore the extra parameter in this manner. It also ruins the readability of the function declarations. This second set of UNUSED's is more general and it is applied within the function like: int function (x){ UNUSED(x); #define UNUSED(x) ((void)x) #define UNUSED(x) x=x #define UNUSED(x) ( *(volatile typeof(x) *)&(x) = (x); ) #define UNUSED(x) if(x); Unfortunately the members of the second set tend to convert the "unused parameter" message into some variant of a "this line does nothing" message on other compilers. For instance, that is what the "x=x" form, which works with gcc does when clang sees it. What I'm wondering is if any of you have a table of compiler identification macros vs. members of the second set, that can be used in a header file to pick the appropriate method for each compiler, so that compilation with the strictest warnings is silent about unused parameters. Like this (this example is entirely made up, I am NOT saying that the associations below are correct): #if defined (__GNUC__) #define UNUSED(x) x=x #elif defined (__CLANG__) #define UNUSED(x) ((void)x) #elif defind (__INTELC__) #define UNUSED(x) ( *(volatile typeof(x) *)&(x) = (x); ) /* etc. */ #endif There is one other method I know of, which is to actually use the parameter "harmlessly", but it has its own issues. For instance to do extern unsigned int junk; and within the function if(x)junk++; With junk defined globally in the c file that holds main(). If the compiler only sees one module at a time it cannot tell if junk will ever be used, so it should not give any warnings. If the program is a single file though, or all modules are compiled together, the compiler will be able to detect that nothing is actually happening and issue warnings to that effect. Thanks, David Mathog [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
C Programming
Table of "safe" methods to suppress "unused parameter" warnings?
Top