Closed teetak01 closed 5 years ago
Originally I decided to use #ifdef
and linker combination to reduce foot print of the library. #ifdef
reduce internal static function calls that is not needed for selected configuration and linker do rest of reduction jobs (require some optimization flag, like -O1
). Reason for this was that number of #ifdef
start growing and makes harder to read the code. It is true that -Wunused-function
causes ~20 errors because of unused function
, but using -Wno-unused-function
silents those errors.
Questions:
-Wunused-function
or -Wnounused-function
) ?-O1
)#ifdef's
or rely on linker functionality to drop unused functions)#ifdef
even it makes code less readable ?@seppo @kjbracey-arm please check this out..
This warning is on by default in most compilers - seems you're doing something which really does tend to provoke it.
We tend to use ifdefs where this arises in Mbed OS, but it doesn't occur that often. Normally stuff that isn't used is not marked static
, which is what prompts the complaint.
I think marking the functions static inline
should shut that warning up in all compilers, with no downside that I can see if it's called exactly once. Or you could stop them being static
.
It's possible the MBED_UNUSED
attribute in mbed_toolchain.h might work, but it's only documented for use on parameters.
most of those functions that causes compiler warning are called only once so inline is just fine for them. It also seems to work as expected so I'll create PR with inline
.
seems that ARM compiler was not happy with inline:
[Error] ns_cmdline.c@1740,0: #1059-D: an entity with internal linkage cannot be referenced within an inline function with external linkage
Hmm have to re-think how to fix this.
It's possible the MBED_UNUSED attribute in mbed_toolchain.h might work, but it's only documented for use on parameters.
Would not like to use mbed-os specific attributes since library is generic and used with other OS's as well...
They should have been set static inline
, not just inline
. They're still private to that C file, right?
seems that static inline
does not silent these warnings:
../../source/ns_cmdline.c:388:39: error: unused function 'goto_beginning_of_history' [-Werror,-Wunused-function]
static inline void goto_beginning_of_history(void);
Are you happy if I just bring them "public" - without static/inline keywords, and ensure they have enough unique names to avoid conflicts with applications.. ?
Okay, that's a bit weird. It must be distinguishing between headers and C files, because it wouldn't complain if there was an unused "static inline" in a header.
Making them publicly visible isn't ideal - it makes the code worse to shut up a compiler warning, which I'm not a fan of.
How about sticking pragma(s) at the top of the file to silence the warnings? When the code isn't wrong, and any change would make it worse, I'd rather shut the compiler up:
#pragma GCC diagnostic ignored "-Wunused-function"
will work for Clang (ARMC6) and GCC. IAR and ARMC5 would need something else.
that's fine for me also. Does anyone have an objection? @SeppoTakalo @teetak01
Description
Bug
mbed-client-cli version b97cbfb3db70058ed66579b7496200f851d386a2