In the function:
void DoSomething(int a, int b) {
SomeOtherFunction(a); }
The compiler (C166) generates the warning unused parameter b. So I tried:
b;
And get warning expression with possibly no effect. So I tried:
void DoSomething(int a, int /*b*/) {
And got warning non standard extension - unnamed parameter!
Anybody got any other ideas?
(void)b;
Also gives warning expression with possibly no effect.
void DoSomething(int a,int) { SomeOtherFunction(a); }
Thanks for that but it gives the same "non standard expression - unnamed parameter" warning as described above.
Oops - didn't see you had tried that. Stupid Keil compiler.
This is an old chestnut - it comes up again and again!
Some compilers are thoughtful enough to provide some kind of #pragma or similar to handle this.
Otherwise, it's a matter of finding some bening bit of code that doesn't then give some other warning - as you've found...
Have you tried
void DoSomething(int a, int b) { b=b; }
"benign"
I have found that works with several compilers:
if (b);
If you want the code to be protable between compilers, you might want to wrap the 'silencing' code by a macro:
#define UNUSED_ARG(x) do { if (x) ; } while (0) /* or whatever */
Besides, it will probably make the code more readable.
I think that the conclusion from this thread is that the solution is not portable - because what "works" on one compiler may not on another.
To make it "portable", you'd need comditional-compilation to select the appropriate construct for the particular compiler...
But the technique of wrapping an "executable" macro in do{...}while(0) is a common one:
c-faq.com/.../multistmt.html
per c166 docs:
#pragma warning disable = 47
http://www.keil.com/support/man/docs/c166/c166_warning.htm
Doesn't seem to be an option to "restore previous setting", though?
Wow, I didn't expect so many helpful replies. Thanks for all the good advice. I also tried the if(b); option but it gives an expression has no effect warning. So, the conclusion seems to be that disabling the warning is the only option.
If it did work I would definitely think an unused() macro would be the way to go.
I don't really like to remove the warning as it has saved me before from doing something done and is good for pointing out potential design issues in your code. I guess I can live with it for now fortunately they are in modules that are rarely recompiled.
Thanks for all the advice...
I don't really like to remove the warning as it has saved me before from doing something
I have to agree here. There should be a possibility to mark a singular parameter. I definitely want a warning like this in general. But I want to turn it off if I keep a parameter to conform with a certain interface.
Lints /* ARGSUSEDn */ comes to mind.