Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Strange warning behavior with gcc and signed/unsigned comparisons

I have the following code :

unsigned int a;
if (a > numeric_limits<int>::max())
   do_stuff();

When compiling, gcc complains about

warning: "comparison between signed and unsigned"

OK, I understand

But, with the following code :

unsigned int a;
if (a > (numeric_limits<int>::max()))
   do_stuff();

The warning is no longer displayed and I really don't know why... Is there any logical reason for such a behavior or am I doing something wrong?!

like image 516
malamioute Avatar asked Sep 22 '11 08:09

malamioute


Video Answer


1 Answers

It's because it is a bug. See bug 50012

like image 119
Esben Mose Hansen Avatar answered Sep 21 '22 00:09

Esben Mose Hansen