Relaxing -Wsign-compare

Morten Welinder terra@diku.dk
Thu Sep 20 12:03:00 GMT 2001


   >   for (i = 0; i < sizeof (foo) / sizeof (foo[0]); i++)

[...]


   I don't think you've chosen a good example -- I'd claim that i should
   be an unsigned int.  Personally, it bugs me that people default to
   loops with int, when 95% of the time they're looping with unsigned
   quantities.

It ought not matter whether the type was "int" or "unsigned int".  In
both cases, the compiler ought to infer that the value will fit in
either type.  Then it can pick whatever instruction sequence it feels
like.  Ah, all the things one could do with infinite time and money...

   It can even give you better code to be looping unsigned,
   since some arithmetic operations can be more efficiently encoded if
   the compiler knows they are on unsigned quantities.

Or the other way around, perhaps.

   I think Kaveh has done some work on the compiler to improve this area
   in 3.1.

Great, thanks!

Morten



More information about the Gcc mailing list