Topic: myInt << 35;


Author: "Warren Seltzer" <a-wseltz@microsoft.com>
Date: 1999/11/11
Raw View
Does the standard say anything about arithmetic shifts of more bits
than the size of the integral type.  I couldn't find anything
in Stroustrup 3rd.  I know what my compilers do, and I know
what my machine instructions do, I just wondered if the Standard
weighed in with its 2 cents...

In particular:

#include <the usual suspects>
    void whatever(const int victim, const int count) {
        int result = victim << count;
        cout << "the result of  " << victim << " << " << count << " is " <<
result << endl;
   }

 main (int argc, char ** argv) {
    whatever (0xFF, 35);
    whatever( 0xFF, 65);  // and so on
}
---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]





Author: "Ron" <nospam@this-address.org>
Date: 1999/11/11
Raw View
Warren Seltzer <a-wseltz@microsoft.com> wrote in message
news:80au5u$3b7@news.dns.microsoft.com...
> Does the standard say anything about arithmetic shifts of more bits
> than the size of the integral type.  I couldn't find anything
> in Stroustrup 3rd.  I know what my compilers do, and I know
> what my machine instructions do, I just wondered if the Standard
> weighed in with its 2 cents...

Section 5.8 (1) says that the behavior of << and >> is undefined if the
right operand is negative or >= the length in bits of the left operand.

-- Ron




[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]






Author: "James Kuyper Jr." <kuyper@wizard.net>
Date: 1999/11/12
Raw View
Warren Seltzer wrote:
>
> Does the standard say anything about arithmetic shifts of more bits
> than the size of the integral type.  I couldn't find anything

Section 5.8 p1: "The behavior is undefined if the right operand is
negative, or greater than or equal to the length in bits of the promoted
left operand."
---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]





Author: Ron Natalie <ron@sensor.com>
Date: 1999/11/12
Raw View
Ron wrote:

> Section 5.8 (1) says that the behavior of << and >> is undefined if the
> right operand is negative or >= the length in bits of the left operand.
>
> -- Ron
Don't I know this.  The X server sources violate this rule all over
the place (assumes that 32_bit_thing >> 32 yields 0).  I was porting
to a system where the shift count is part of the instruction and only
5 bits were allocated.  If you do x>>32 the compiler silently entered
zero in that field (yes a warning would have been nice).

_Ron
---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]