This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: C/C++ Bug (shifting chars.)


On Tue, 21 Jul 1998, Sergei Organov wrote:

: The following program prints incorrect result "7f ffffffff" 
: (should be "ffffffff ffffffff", I believe). Note, this happens 
: only for [signed/unsigned] char types; int works well. (gcc2.7.2 
: gives the same wrong result.)

Solaris's SunPro C compiler produces the same result:  "7f ffffffff".

I haven't read my C books lately, but in C++ the << and >> operators
(whether used for shifting or insertion/extraction) bind to the right, not
to the left.  In other words,

    c1 = c << 3 >> 3;

is actually evaluating as:

    c1 = c << (3 >> 3);

See how it gets 0x7f?  It's shifting c by 0.  :)

-- 
-- Todd Vierling (Personal tv@pobox.com; Bus. todd_vierling@xn.xerox.com)



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]