This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Question for "<<"

Hi all

I write a sample code like

a = 1 << b;

when b = 0 , The result for a will get 2

If I uncheck "Enable ANSI integer promotion rules " ,It will get correct answer 1

can anyone tell me why ??

Thanks a lot

Parents
  • Thanks for replay

    I have a ready to this ,Please see it

    #define ENABLE 1
    uchar volatile xdata *ptr_reg=0x8000;
    bug0 =0;
    bug1 =0;

    uchar b = pre_reg[0];

    a = (ENABLE << b);

    if ( b != 0 ) bug0++;
    if ( a != 1 ) bug1++;

    after I run this ,bug0 is zero ,but bug1
    is nonzero.

    I also have run this code in VC60,and it work fine.

    Thanks for your kind help

Reply
  • Thanks for replay

    I have a ready to this ,Please see it

    #define ENABLE 1
    uchar volatile xdata *ptr_reg=0x8000;
    bug0 =0;
    bug1 =0;

    uchar b = pre_reg[0];

    a = (ENABLE << b);

    if ( b != 0 ) bug0++;
    if ( a != 1 ) bug1++;

    after I run this ,bug0 is zero ,but bug1
    is nonzero.

    I also have run this code in VC60,and it work fine.

    Thanks for your kind help

Children