This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Signed-unsigned comparison question
- From: Zoltan Kocsi <zoltan at bendor dot com dot au>
- To: gcc at gcc dot gnu dot org
- Date: Fri, 8 Mar 2019 10:40:06 +1100
- Subject: Signed-unsigned comparison question
Gcc 8.2.0 (arm-none-eabi) throws a warning on the following construct:
uint32_t a;
uint16_t b;
if ( a > b ) ...
compaining that a signed integer is compared against an unsigned.
Of course, it is correct, as 'b' was promoted to int.
But shouldn't it be smart enough to know that (int) b is restricted to
the range of [0,65535] which it can safely compare against the range of
[0,0xffffffffu]?
Thanks,
Zoltan