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?
The cast to void still gives the "expression with possibly no effect" warning. It's a good idea though, #define UNUSED(p) ((p)=(p)) works nicely with no warnings. Stefan
Very strange... Don't see this warning with the mechanism... I'll try to look at it more close. --Geert
Ah! Self-assignment was the old trick that I had forgotten. Thanks! It seems to get along well with C51. From the point of view of language elegance, simply leaving the parameter unnamed is my favorite method, but it's not strictly legal C.
Would self-assignment consume too many machine cycles? I've a function wchich provides a delay based on the parameter in microseconds( I estimate the number of instructions necessary to be run based on the microcontroller speed, for a specified number of micro-seconds just by looping based on the input parameter). But rather than using the parameter(unsigned long)in my function, I directly extract it from the registers so that I save time and therefore get the exact delay. So, I end up with the warning unused parameter since the parameter isn't being used in the function. Any comments? -Sundeep
I think you'll find the compiler optimises it out completely, so it shouldn't add any execution time to your function. Stefan
Stephan, I checked again the construction I proposed yesterday, because you were saying it still generated the warning "expression with possibly no effect":
#define UNUSED(p) ( (void)(p) )
Geert, I'm using C51 v7.01. Disabling all warnings via Project->Options for target->C51->Warnings certainly supresses the warning. Others have mentioned that it is possible to disable individual warnings globally, maybe you should check this? Stefan
Stefan, Just for information: the warning level is 2, meaning 'Errors and possbily warnings'. There are no individual warnings switched off in my case (BL51 Misc tab in Options for Target: xxx). Still a mystery for me... --Geert
unfortunately I forgot to say that I am working with the actual release of C166. Leo