We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
Any good suggestions for silencing the "unused parameter" warnings on a per-case basis? As opposed to turning them all off via compiler option, that is. I'd like to avoid the warnings for placeholder routines and API-required parameters that happen not to be needed in some routines, while retaining the warning for truly unneeded parameters. Stupid coding tricks I've used in the past with other tools include a cast to void (which just substitutes a "expression may have no effect" warning with C51, no net gain) and commenting out the parameter name (which just earns a "unnamed parameter" error from C51). If "unnamed parameter" were just a warning, I'd probably opt for that and squelch it globally, since it's not likely to occur accidentally, but C158 is an error and prevents compilation. Any favorite tricks to share?
I compared:
#define UNUSED(p) if(p){}
That's a good one! I have definitely seen the optimiser removing "unconditional" ifs like this. Have you experimented to find the minimum optimisation level to do this? Have you tried this was other compilers? The trouble I often find is that this kind of trick stops the "unused parameter" warning, but gives a "code with no effect" (or similar) warning instead! :-(
It did not give me a code with no effect warning, and was with all optimisation on.
"It did not give me a code with no effect warning" Keil seldom (if ever) does, but what about other Compilers? eg, MSVC? Borland?
"but what about other Compilers? eg, MSVC? Borland?" Who cares? Stefan
For attempts at portable code, I just go with a macro: #define UNUSED(arg) blah arg blah blah which is tossed into the same file as the definitions for U8/16/32s, Bool, FAR / FAST / NEAR / BULK / ROM, and other compiler-specific fiddly keywords. Then, you just have different definitions for the macro that best avoid compiler and lint warnings on that particular platform.