On Jun 4, 2008, at 2:38 PM, Jens Alfke wrote: I haven't tried -Wextra. But you can turn options off individually using -Wno-[option-name]. The GCC docs, which are down somewhere inside the ADC Ref Lib, have a chapter that lists all the warning flags.
I believe there is also a #pragma or something like that to tell the compiler that a variable or parameter is deliberately unused, which will suppress warnings about it.
Thanks Jens! Adding #pragma unused (paramName)
to the top of the function (inside the block) does suppress the warning.
Googling this led me to some posts that imply this #pragma is deprecated but still functioning. I saw references to using __unused__ instead, but only saw examples of that with C function prototypes, and couldn't get it to work with Obj-C.
~~~
On Jun 4, 2008, at 2:38 PM, Stefan Werner wrote: Is there some other way I can inform the compiler (and a future maintainer) that the parameter is intentionally not used?
I'm not sure how it works for Objective-C, but in C and C++ you tell gcc that a parameter is unused by not naming it. Instead of:
int foo (int parmUsed, bool parmUnused) { return parmUsed+1; }
write
int foo (int parmUsed, bool) { return parmUsed+1; }
Thanks for the suggestion, but doing such in Objective-C leads to an error.
~~~
On Jun 4, 2008, at 2:33 PM, Jean-Daniel Dupas wrote: You should not used unused argument as it prevent the compiler to optimize the function.
I agree -- which is why I posted. All warning are not usefull and should not be used. It's meaningless to enabled all warning and try to fight the compiler to prevent them.
For now I'd like to try and achieve warning-free code and do so by working with the compiler, and by the use of "intentional" (i.e., making my intentions explicit (even if verbose)) rather than "lazy" coding (which is in my bones and has never before been an issue for me).
Some warning like unused param should be ignored (and so disabled).
Yes, this one in particular seems a nuisance as the failure to use a parameter that is needed will likely lead to functional failure. But then, isn't this the purpose of warnings -- to catch potential failures before they become actual failures? I ask that hetorically as I think we have ventured far into "style" territory with this.
|