Patch to elide sign compare warning in ?:

Michael Hayes
Sat Apr 8 02:33:00 GMT 2000

Kaveh R. Ghazi writes:
 > We already eliminate sign compare warnings for "(unsigned) > 64".
 > This patch eliminates the sign compare warnings for these kinds of
 > expressions: "(unsigned) > (foo ? 64 : 32)"

On the related subject of unsigned compare warnings, my biggest
annoyance is with something like:

#define R0_REGNO   0
#define R7_REGNO   7

#define IS_LOW_REGNO(r) ((((r) >= R0_REGNO) && ((r) <= R7_REGNO)))

int foo (unsigned int regno)
  return IS_LOW_REGNO (regno);

In this case, a little bit of defensive programming leads
to the warning:
/tmp/foo.c:8: warning: comparison of unsigned expression >= 0 is always true

I can see merit in emitting the warning if there is a single test but
when testing a bracketed range I feel the warning is a little over the
top.  Is there a simple solution?


More information about the Gcc-patches mailing list