Re: value of the constant expression 1<<(1?1:1) < 0x9999
- From: Peter Nilsson <airia@xxxxxxxxxxx>
- Date: Tue, 29 Apr 2008 15:35:06 -0700 (PDT)
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
.
- References:
- value of the constant expression 1<<(1?1:1) < 0x9999
- From: Francois Grieu
- value of the constant expression 1<<(1?1:1) < 0x9999
- Prev by Date: value of the constant expression 1<<(1?1:1) < 0x9999
- Next by Date: Re: 128 bit integer code needed
- Previous by thread: value of the constant expression 1<<(1?1:1) < 0x9999
- Next by thread: Re: value of the constant expression 1<<(1?1:1) < 0x9999
- Index(es):
Relevant Pages
|