C99 standard(p 6.3.1.8) state that:
Otherwise, if the operand that has unsigned integer type has rank greater or equal to the rank of the type of the other operand, then the operand with signed integer type is converted to the type of the operand with unsigned integer type.
but when I try to compile such piece of code(it is not real application code, just example)
signed long int x = -1;
unsigned long int y = ULONG_MAX;
if (x < y)
printf("1:%p %p \n", (void *) x, (void *) y);
signed short int xx = -1;
unsigned short int yy = USHRT_MAX;
if (xx < yy)
printf("2:%p %p \n", (void *) (intptr_t) xx, (void *) (intptr_t) yy);
I have different behavior with variable that have different types. That is I have output as follows:
2:0xffffffff 0xffff
I am using Linux and have 32-bit processor, for compilation I am using gcc and clang
gcc -std=c99 -o some \
-pedantic -Wextra -Wall -pedantic-errors \
-Wshadow -Waddress -Wformat \
./some_src.c
clang -std=c99 -o some \
-pedantic -Wextra -Wall -pedantic-errors \
-Wshadow -Waddress -Wformat \
./some_src.c