473,406 Members | 2,345 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

is (variable >> 32) undefined?

I just discovered that sometimes on some compilers it is true that
(variable >> 32) == variable where variable is an unsigned long and on
these platforms an unsigned long is 32 bits. Is bit shifting a
variable in the manner undefined by the standard or is this just a bug
in the compiler?


examples:
in borland 5.5.1 the following code prints 1, I would expect it to be 0
unsigned long low = 1;
low >>= 32;
cout << low;

I also found a similar problem in visual studio but weather or not
(low>>32) == low or 0 is apparently dependent upon what (seeming
independent) statements precede the shift.

Jul 19 '05 #1
3 1809
Davis King wrote :
I just discovered that sometimes on some compilers it is true that
(variable >> 32) == variable where variable is an unsigned long and on
these platforms an unsigned long is 32 bits. Is bit shifting a
variable in the manner undefined by the standard or is this just a bug
in the compiler?


I believe this is in compliance with the Standard. As I recall, both
negative and too large positive (when value goes beyond the size of a
variable) shifts produce undefined results.

Nikolai Borissov
Jul 19 '05 #2
On Sat, 27 Sep 2003 12:45:04 -0700, Davis King <da*******@mail.com>
wrote in comp.lang.c++:
I just discovered that sometimes on some compilers it is true that
(variable >> 32) == variable where variable is an unsigned long and on
these platforms an unsigned long is 32 bits. Is bit shifting a
variable in the manner undefined by the standard or is this just a bug
in the compiler?


examples:
in borland 5.5.1 the following code prints 1, I would expect it to be 0
unsigned long low = 1;
low >>= 32;
cout << low;

I also found a similar problem in visual studio but weather or not
(low>>32) == low or 0 is apparently dependent upon what (seeming
independent) statements precede the shift.


If the shift count for an integer type is negative or greater than or
equal to the number of bits, the result is undefined. The compiler is
absolutely correct.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++ ftp://snurse-l.org/pub/acllc-c++/faq
Jul 19 '05 #3

"Davis King" <da*******@mail.com> wrote in message news:bl**********@news.cis.ohio-state.edu...
I just discovered that sometimes on some compilers it is true that
(variable >> 32) == variable where variable is an unsigned long and on
these platforms an unsigned long is 32 bits. Is bit shifting a
variable in the manner undefined by the standard or is this just a bug
in the compiler?


It's undefined behavior if the number of bits in the shift is equal or greater
than the number of bits in the size of the other operand. I have worked
on one implementation where the above would be a no op rather than
a store of zero.
Jul 19 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: DC Gringo | last post by:
I'm getting a "BC30451: Name 'CRListType' is not declared." error Here's the top of the page where I'm getting stuck... <%@ Control Language="vb" AutoEventWireup="false"...
1
by: Jan Plastenjak | last post by:
I got this error: Error Type: Microsoft VBScript runtime (0x800A01F4) Variable is undefined: 'myapp' When I was doing this: Set myapp = Server.CreateObject("MyAppCOM.MyApp.1")
1
by: Xeon | last post by:
Hi, I'm trying this code snippet below but the parser (sablotron) returns error : <xsl:choose> <xsl:when test="some test case"> <xsl:variable name="test" select="0"/> </xsl:when>...
4
by: troloo | last post by:
Hello, I hope you can help me :)) The story goes as follows: I have a class with different methods and member variables. I store pointers to objects of this class inside a vector. Now, I would like...
8
by: Jim Moon | last post by:
Hi. I'm curious about this syntax: <variable>=function(){...} I'm not finding a definition of this syntax, but I see it used at this website:...
49
by: matty | last post by:
Hi, I recently got very confused (well that's my life) about the "undefined" value. I looked in the FAQ and didn't see anything about it. On...
10
by: Phil Latio | last post by:
Just playing around with the idea of using a html template page to seperate the code from design. Very basic example below <html> <!-- hello.html --> <body> Hello <b><?php echo $message...
5
by: Reshmi Jacob | last post by:
Hello Can I have more than one variable assign to a select clause in a trigger. How? My stmt creates an error SELECT FLD1 into VAR1, FLD2 into VAR2 FROM MYTABLE; ERROR shown at the second...
1
by: jcgurango | last post by:
ok, I have 2 pages, one has a code on it, and the other has a textbox with a button....... I wanna make it so that when you press the button, whatever is on the textbox will be the value of the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.