F
Francois Grieu
Hello,
one of my C compiler (Keil C51) evaluates the constant expression
1<<(1?1:1) < 0x9999
to the value 1.
// this returns 0, much to my surprise
unsigned char bug4_a(void)
{
return 1<<(1?1:1) < 0x9999;
}
Can this find a satisfactory explanation under some definition of the
C language ?
Note: I still get 0 for
return 1<<(1?1:1) < (unsigned)0x9999;
return 1<<(unsigned char)(1?1:1) < 0x9999;
but I get 1 (as I expect) for
return 1<<(1) < 0x9999;
return (unsigned)1<<(1?1:1) < 0x9999;
return 1u<<(1?1:1) < 0x9999;
return 1<<(1?1:1) < 0x7777;
return 1<<(1?1:1) == 2;
#if 1<<(1?1:1) < 0x9999
return 1;
#else
return 0;
TIA,
Francois Grieu
one of my C compiler (Keil C51) evaluates the constant expression
1<<(1?1:1) < 0x9999
to the value 1.
// this returns 0, much to my surprise
unsigned char bug4_a(void)
{
return 1<<(1?1:1) < 0x9999;
}
Can this find a satisfactory explanation under some definition of the
C language ?
Note: I still get 0 for
return 1<<(1?1:1) < (unsigned)0x9999;
return 1<<(unsigned char)(1?1:1) < 0x9999;
but I get 1 (as I expect) for
return 1<<(1) < 0x9999;
return (unsigned)1<<(1?1:1) < 0x9999;
return 1u<<(1?1:1) < 0x9999;
return 1<<(1?1:1) < 0x7777;
return 1<<(1?1:1) == 2;
#if 1<<(1?1:1) < 0x9999
return 1;
#else
return 0;
TIA,
Francois Grieu