So i have some code like this:
void foo (int, int);
void bar ( )
{
//Do Stuff
#if (IMPORTANT == 1)
foo (1, 2);
#endif
}
One solution is via function attributes.
void foo (int, int) __attribute__ ((unused));
This will tell gcc not to issue an unused function warning for the function foo
. If you're worried about portability, you can define a macro UNUSED_FUNCTION_ATTRIBUTE
that expands to __attribute__ ((unused))
with compilers that support attributes, but expands to nothing otherwise.
I'm fairly sure the relevant warning option is this one:
-Wunused-function
Warn whenever a static function is declared but not defined or a non-inline static function is unused. This warning is enabled by -Wall.
So the warning should only be given for a static
function, interesting. Makes sense. If a function is static
it can only be used within the current file, so its definition must also be in this file.
And declaring it static inline
avoids the warning, without resorting to ugly macros or compiler-specific pragmas or attributes.
#define SUPPRESS_UNUSED_WARN(var) \
int _dummy_tmp_##var = ((int)(var) & 0)
not work in IAR, change to this will work:
#define SUPPRESS_UNUSED_WARN(var) \
void _dummy_tmp_##var(void) { (void)(var); }