incorrect signed/unsigned conversions for short and char
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
gcc-4.2 (Ubuntu) |
New
|
Undecided
|
Unassigned |
Bug Description
Binary package hint: gcc-4.2
Release:
Description: Ubuntu 8.04
Release: 8.04
Version information:
gcc-4.2:
Installed: 4.2.3-2ubuntu7
Candidate: 4.2.3-2ubuntu7
Version table:
*** 4.2.3-2ubuntu7 0
500 http://
100 /var/lib/
Description:
Signed/unsigned comparisons yield unexpected results in some cases. C code that exercises this is appears below. The expected result (tested on previous versions of gcc) is that it will print the gcc version and nothing else.
#include <stdio.h>
int main() {
long l = 0L;
unsigned long ul = 0x80000000L;
int i = 0;
unsigned int ui = 0x80000000;
short s = 0;
unsigned short us = 0x8000;
char c = 0;
unsigned char uc = 0x80;
printf("Using gcc version %s\n\n", __VERSION__);
if (l > ul)
if (i > ui)
printf("int 0x%08x > unsigned int 0x%08x evaluates to true\n", i, ui);
if (s > us)
if (c > uc)
if (((long) 0L) > ((unsigned long) 0x80000000L))
if (((int) 0) > ((unsigned char) 0x8000000))
if (((char) 0) > ((unsigned short) 0x8000))
if (((char) 0) > ((unsigned char) 0x80))
return 0;
}
$ gcc -Wall test.c -o test
$ ./test
Using gcc version 4.2.3 (Ubuntu 4.2.3-2ubuntu7)
short 0x0000 > unsigned short 0x8000 evaluates to true
char 0x00 > unsigned char 0x80 evaluates to true