Re: [hatari-devel] warning with ARRAYSIZE macro

[ Thread Index | Date Index | More lists.tuxfamily.org/hatari-devel Archives ]


On 07.09.2016 22:40, Nicolas Pomarède wrote:
> Hi
> 
> when compiling with mingw for windows, nearly all uses of ARRAYSIZE
> generate a warning :
> 
> 
> src/gemdos.c:3200:23: warning: comparison between signed and unsigned
> integer expressions [-Wsign-compare]
>   for (used = i = 0; i < ARRAYSIZE(ForcedHandles); i++)
> 
> we have this for ARRAYSIZE :
> 
> #ifndef ARRAYSIZE
> #define ARRAYSIZE(x) (int)(sizeof(x)/sizeof(x[0]))
> #endif
> 
> As sizeof returns a >= 0 value, we should cast to "unsigned int", or
> even not cast at all, but cast the value on the left side of the
> comparison to "unsigned int" instead ("i" in that case).
> 
> There's no warning with GCC/Clang, but under mingw, I guess ARRAYSIZE is
> already defined with a different cast.
> 
> Should we cast everything to unsigned to avoid warning for all compilers ?

Changing our macro to cast to unsigned won't help here since on MinGW,
it will still use their macro instead. You'd need #undef ARRAYSIZE or so
instead.
Or you could rename our macro. I've seen ARRAY_SIZE in other projects
that also support MinGW, so that could maybe work better.

 Thomas




Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/