|
|
Francois Grieu wrote:
> Hello,
>
> one of my C compiler (Keil C51) evaluates the constant expression
> 1<<(1?1:1) < 0x9999
> to the value 1.
Correct...
1 << (1?1:1) < 0x9999
(1 << (1?1:1)) < 0x9999
(1 << 1) < 0x9999
2 < 0x9999
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 ?
No.
> Note: I still get 0 for
>
> return 1<<(1?1:1) < (unsigned)0x9999;
>
> return 1<<(unsigned char)(1?1:1) < 0x9999;
Integer promotion must be applied, but it is incidental. They
should all return 1 on a conforming implementation.
--
Peter
|
|