[hatari-devel] warning with ARRAYSIZE macro

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


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 ?

Nicolas



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