Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » Extra libraries, Code snippets, applications etc. » C++ language problems and code snippets » Time for little quiz!
Re: Time for little quiz! [message #2295 is a reply to message #2294] Thu, 06 April 2006 16:25 Go to previous messageGo to previous message
mirek is currently offline  mirek
Messages: 14267
Registered: November 2005
Ultimate Member
victorb wrote on Thu, 06 April 2006 10:17

Graeme,

If I understand your previous topic well, you are stating that there might be an inconsistency between GCC and VC because they do not handle integer the same way and you are afraid this might cause errors with "(-q >> 31) & 1".

However if you look at the following URL:
http://msdn2.microsoft.com/en-US/library/7x62187h(VS.80).aspx
You will see that VC handle right shifts the same way as GCC by etending the sign bit (for negative number as "-q").

VC:
"Right shifts preserve the sign bit. When a signed integer shifts right, the most-significant bit remains set. When an unsigned integer shifts right, the most-significant bit is cleared."

GCC:
"Signed >> acts on negative numbers by sign extension."

Victor


Let me just note that for "(x >> 31) & 1" expression, as long as int is 32 bits or more, it does not matter how sign extension works Wink

Mirek
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: STL multimap
Next Topic: explanation of c++ typedef line
Goto Forum:
  


Current Time: Mon Sep 15 19:50:09 CEST 2025

Total time taken to generate the page: 0.42583 seconds