Re: [hatari-devel] warning with ARRAYSIZE macro

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


Hi,

On 09/07/2016 11:40 PM, Nicolas Pomarède wrote:
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]))
  -----------------------^

Signed.

#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.

I assume some mingw header has ARRAYSIZE declared without (int) cast.

Remove ifndef from around the define in our header so that you
get warning telling where where mingw defines ARRAYSIZE (and
how it defines it).

Then make sure that this place contains ifndef, and if it does,
just move our definition to be included before mingw one.


Should we cast everything to unsigned to avoid warning for all compilers ?

We need first to know why exactly it works differently with mingw.
Otherwise changing things would just get warnings with other compiler.


	- Eero



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