comp.lang.c
[Top] [All Lists]

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

Subject: value of the constant expression 1<<(1?1:1) < 0x9999
From: Francois Grieu
Date: Tue, 29 Apr 2008 15:03:04 -0700 PDT
Newsgroups: comp.lang.c

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

<Prev in Thread] Current Thread [Next in Thread>
Privacy Policy