I find out that Apple uses the following declaration in OSAtomic.h header:
inline static int32_t OSAtomicDecrement32( volatile int32_t *__theValue )
{ return OSAtomicAdd32( -1, __theValue); }
I am getting the following warning when including it and compiling:
warning: 'int32_t OSAtomicDecrement32(volatile int32_t*)' defined but not used
That is true, but I would like to know answers to the following:
-
Do they really need to have this symbol defined in some library (to get rid of this warning)? If the function OSAtomicDecrement32 can be created only by calling OSAtomicAdd32, why one can’t define this in a header directly? Should they use #define OSAtomicDecrement32 …body.. instead?
-
If I don’t call OSAtomicDecrement32 in my program, why does it complain that symbol OSAtomicAdd32 is undefined (when I don’t link with a library which defines it)? It is inline, I thought that when I don’t use something, the compiler would strip it off…
Thanks for explaining it to me!
I guess the reason for gcc complaining about this is the
statickeyword which results in code for this function to be emitted in any compilation unit. They just shouldn’t do it like this. Either they’d useinlinewithoutstaticand provide the symbol in just one library, libc e.g.always_inlinebut never
static.BTW, gcc has extension for this operations (prefixed with
__syncIIRC) that would be portable to other systems where there is gcc, clang, icc, opencc…Perhaps you could get around this by adding some arguments to the gcc call. Try
-std=c99or switch off the corresponding warning.