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 #2293 is a reply to message #2292] Thu, 06 April 2006 15:56 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13050
Registered: November 2005
Ultimate Member
gprentice wrote on Thu, 06 April 2006 08:29
FWIW - Visual C++ and GCC describe their implementation defined behavior for integer bit operations - most likely all GCC versions do the sign extension mentioned and all VC versions treat signed as unsigned.

[url=http://msdn2.microsoft.com/en-US/library/dxda59dh(VS.80).aspx

http://msdn2.microsoft.com/en-US/library/dxda59dh(VS.80).asp x[/url]

http://gcc.activeventure.org/Integers-implementation.html#In tegers-implementation

Graeme



Yes, this implementation defined behaviout is in fact quite consistent across all platforms. I guess that expecting behaviour you describe would not hurt portability in any way....

Mirek
Re: Time for little quiz! [message #2294 is a reply to message #2292] Thu, 06 April 2006 16:17 Go to previous messageGo to next message
victorb is currently offline  victorb
Messages: 78
Registered: December 2005
Location: Nice, France
Member
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
Re: Time for little quiz! [message #2295 is a reply to message #2294] Thu, 06 April 2006 16:25 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13050
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
Re: Time for little quiz! [message #17891 is a reply to message #2295] Tue, 02 September 2008 00:04 Go to previous messageGo to next message
nixnixnix is currently offline  nixnixnix
Messages: 415
Registered: February 2007
Location: Kelowna, British Columbia
Senior Member
ok I am not quite up to understanding the full consequences of the above conversation. However, the bit (excuse the pun) that interests me is:

how many bits does an "int" have when I compile on a 64 bit OS (linux or vista - I am trying both)?

If I want my documents to load and save (using Serialize(Stream&)) between 32 and 64 bit implementations of my software, do I need to replace all "int" with "int32"? I am guessing this is so but what else will I need to change please?

char is still 16 bit right?
float is always 32 bit right?
double is always 64 bit right?
what about bool?
what about String?

Nick

[Updated on: Tue, 02 September 2008 00:06]

Report message to a moderator

Re: Time for little quiz! [message #17892 is a reply to message #17891] Tue, 02 September 2008 08:56 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13050
Registered: November 2005
Ultimate Member
[quote title=nixnixnix wrote on Mon, 01 September 2008 18:04]ok I am not quite up to understanding the full consequences of the above conversation. However, the bit (excuse the pun) that interests me is:

how many bits does an "int" have when I compile on a 64 bit OS (linux or vista - I am trying both)?

If I want my documents to load and save (using Serialize(Stream&)) between 32 and 64 bit implementations of my software, do I need to replace all "int" with "int32"? I am guessing this is so but what else will I need to change please?
[quote]

It "depends".

With x86-64, int is still 32 bits. And in fact, AFAIK, this is the most common arrangement for 64-bit systems.

To get "true" 64-bit integer, types vary more, but with U++, you can just use "int64".

Quote:


char is still 16 bit right?



char is always 8 bit.

wchar is now 16 bit, but it seems like we have to go 32-bit soon. But that should not affect the existing code too much.

Quote:


float is always 32 bit right?
double is always 64 bit right?



Yes.

Quote:


what about bool?



Frankly, I do not know Smile But I believe it is 1 for both GCC and MSC.

Quote:


what about String?



Current implementation 16. May change (before 2007, it was equal to sizeof(void*)).

Mirek
Re: Time for little quiz! [message #17914 is a reply to message #17892] Tue, 02 September 2008 21:54 Go to previous messageGo to next message
nixnixnix is currently offline  nixnixnix
Messages: 415
Registered: February 2007
Location: Kelowna, British Columbia
Senior Member
Quote:


To get "true" 64-bit integer, types vary more, but with U++, you can just use "int64".

Quote:



char is still 16 bit right?




char is always 8 bit.



doh! Embarassed thats what i meant to write.

So there is no reason you can think of why a document serialized by a 32 bit compilation of a program might not be able to be read by a 64 bit compilation of the same program?

Nick


Re: Time for little quiz! [message #17934 is a reply to message #17914] Wed, 03 September 2008 14:18 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13050
Registered: November 2005
Ultimate Member
nixnixnix wrote on Tue, 02 September 2008 15:54


So there is no reason you can think of why a document serialized by a 32 bit compilation of a program might not be able to be read by a 64 bit compilation of the same program?



Now I am a little bit confused... Smile

Are we speaking about Serialize(Stream&) ?

If yes, this is explicitly programmed to be platform independed. So even if "int" would be 64-bit, Serialize would store only (lower) 32.

Mirek
Re: Time for little quiz! [message #17936 is a reply to message #17934] Wed, 03 September 2008 16:38 Go to previous messageGo to next message
nixnixnix is currently offline  nixnixnix
Messages: 415
Registered: February 2007
Location: Kelowna, British Columbia
Senior Member
Ok, good to know. Thanks. It must be something else.

Have you tested much under 64 bit windows? I notice that all the code which distinguishes between windows and linux uses the #ifdef PLATFORM_WIN32 directive. Is this flag set when one is compiling 64 bit code under windows?

Nick
Re: Time for little quiz! [message #17938 is a reply to message #17936] Wed, 03 September 2008 16:51 Go to previous messageGo to next message
mrjt is currently offline  mrjt
Messages: 705
Registered: March 2007
Location: London
Contributor
Win32 is simply the name of the API introduced with Window 95 and used in all Windows versions since then (though perhaps not for very much longer). So yes, it is.
Re: Time for little quiz! [message #18027 is a reply to message #17936] Sun, 07 September 2008 10:12 Go to previous message
mirek is currently offline  mirek
Messages: 13050
Registered: November 2005
Ultimate Member
nixnixnix wrote on Wed, 03 September 2008 10:38

Ok, good to know. Thanks. It must be something else.

Have you tested much under 64 bit windows? I notice that all the code which distinguishes between windows and linux uses the #ifdef PLATFORM_WIN32 directive. Is this flag set when one is compiling 64 bit code under windows?

Nick


IMO, you can say that Win32 is a subset of Win64... Smile

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


Current Time: Sat Jan 23 09:18:45 CET 2021

Total time taken to generate the page: 0.01037 seconds