This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Re: C/C++ Bug (shifting chars.)
- To: Sergei Organov <osv at javad dot ru>
- Subject: Re: C/C++ Bug (shifting chars.)
- From: Todd Vierling <tv at pobox dot com>
- Date: Tue, 21 Jul 1998 12:00:39 -0400 (EDT)
- cc: Egcs Bugs <egcs-bugs at cygnus dot com>
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)