Re: value of the constant expression 1<<(1?1:1) < 0x9999



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
.



Relevant Pages

  • value of the constant expression 1<<(1?1:1) < 0x9999
    ... one of my C compiler (Keil C51) evaluates the constant expression ... // this returns 0, much to my surprise ... unsigned char bug4_a ...
    (comp.lang.c)
  • Re: value of the constant expression 1<<(1?1:1) < 0x9999
    ... one of my C compiler (Keil C51) evaluates the constant expression ... Thje rest was hopefully correct. ...
    (comp.lang.c)
  • Re: float.h and math.h
    ... The hex floats are "new" in C99 aren't they..... ... That's because it's not a constant expression. ... And as GCC 331 is still C89 I guess that the sort of fudges I am using ... So I need a "C" compiler that will, at least cross compile to the I370 (not ...
    (comp.lang.c)
  • Re: Linux 2.6.27.27
    ... is competent with gcc. ... that's very much a compiler bug. ... unsigned char i, ... ... infinite loop, even though it clearly is not. ...
    (Linux-Kernel)
  • Re: PLEASE READ (was Re: recursive proofs)
    ... how would I have had Nash fix it properly? ... you could have told him to write the constant expression in a manner ... > that adheres to the C standard, instead of suggesting he use a compiler ...
    (comp.programming)