c/2102: no warning when comparing (unsigned int) with (int)

philippe.jouguet@vdldiffusion.com philippe.jouguet@vdldiffusion.com
Mon Feb 26 09:06:00 GMT 2001


>Number:         2102
>Category:       c
>Synopsis:       no warning when comparing (unsigned int) with (int)
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          accepts-illegal
>Submitter-Id:   net
>Arrival-Date:   Mon Feb 26 09:06:01 PST 2001
>Closed-Date:
>Last-Modified:
>Originator:     philippe jouguet
>Release:        gcc version 2.96 20000731 and gcc version egcs-2.91.66 19990314/Linux (egcs-1.1.2 release)
>Organization:
>Environment:
linux pentium III kernel 2.2.14-5.0
linux pentium III kernel 2.2.16-22
>Description:
sizeof(..) is an unsigned int and gcc does not print any warning
when (int) is compared with (unsigned int)

A little program :
-----
#include <stdio.h>
int main(int argc, char ** argv)
{
int val ;

val = -1 ;
if (val < sizeof(long)) {
printf("%d < %d\n", val, sizeof(long));
}
else {
printf("BUG %d >= %d\n", val, sizeof(long));
}
return(0);
}
------
Compiling :
gcc -Wall tst.c   -o tst 
-> NO WARNING printed
Exec :
./tst
Result :
BUG -1 >= 4

>How-To-Repeat:

>Fix:
the solution is a warning compilation when we make a comparison between unsigned and signed.
It might be possible to add also this feature : sizeof() operator return a signed int and not a size_t in conformity with the C normalisation.
http://www.physik.fu-berlin.de/edv_docu/documentation/cc-5.2/C-Language-Reference-Manual.html/DOCU_061.HTM#size_sec
>Release-Note:
>Audit-Trail:
>Unformatted:



More information about the Gcc-bugs mailing list