When I first started with the Arduino environment I noticed that it had File | Preferences | Compiler Warnings
set to None
, so I set it to All
- and there were many, many warnings in the supplied libraries! So I quickly set it to None
again - until later.
Well, "later" is now, and I started going through the warnings to fix the code to quiet the compiler.
Note that I don't want to disable any warnings - I want to placate the compiler at each spot so that it says to itself "No problem here!"
- If the compiler complains of an unused variable, I comment out the variable;
- If it complains of a signed/unsigned comparison, I change the type;
- If it complains of an unused parameter in a function, I...
...hmmm. If this was C++, I'd simply comment out the parameter name, leaving the type naked:
void Fn(int /*param*/) {
} // Fn(param)
Arduino reports:
error: parameter name omitted
But that isn't legal in C. With some compilers you can use the __unused
attribute:
void Fn(int __unused param) {
} // Fn(param)
Arduino reports:
error: expected ';', ',' or ')' before 'param'
It's interpreting__unused
as the actual parameter name
or if they're fussy:
void Fn(int __attribute__((unused)) param) {
} // Fn(param)
Arduino reports:
warning: unused parameter 'param' [-Wunused-parameter]
That's not the correct__attribute__
, obviously
So none of the above work in the Arduino environment. Suggestions?
I've been programming in C and C++ for over twenty years, and I know that the #1 thing you should always do is ask the compiler to tell you about everything it notices. You need a warning-free compile at all times! Otherwise, you spend hours or days trying to find a bug - only to discover that the compiler has been warning you about it all along...
void f(int) {...}
idiom should work in the C++ files. I agree it's a shame the core generates so many warnings. – Edgar Bonet Jun 17 '16 at 8:12