|
||||||||||||||||||
Add Forum to Favorites | Send Topic To a Friend | View Forum FAQ | Track this topic |
Last Thread Next Thread ![]() |
| 64-bit sizeof's |
|
![]() Imgelling Member since: 2/17/2007 From: Lexington, KY, United States |
||||
|
|
||||
| I have found a few pages describing 64-bit sizes on unix (though I am looking for Windows), and even one page lists different versions of 64-bit storage. So I would like to ask, 1. Is there a standard sizeof for int,short,char, etc for 64-bit operating systems? 2. If so, does Windows adhere to them ? 3. If not, I have a borrowed a AMD 64-bit duel core something or another (Its my brother's, he went off to do stuff in Iraq) running Vista 64. Would a short on that system be a short on 32-bit? I know an int shouldn't be. 4. If a char is 8bits on either system, and a short is 16bits, but an int is either 32 or 64, what is 32 bits on a 64-bit system and would that 32bit be forced (padded) to 64bit anyways? Or is this just something I would have to test for myself? Thanks for your time! |
||||
|
||||
![]() bradbobak Member since: 10/7/2004 From: Canada |
||||
|
|
||||
| If you are using C or C++, sizes of types don't have to be the same across different systems. afaik, a short must be >= char, an int >= short and a long >= int. You can always use sizeof(type) to test in your app. There are on some compilers other types such as int32_t, int64_t, which specify the bit size, but from what I know these are not standard across all implementations. If you are sending these types across a network or somesuch, you are better off to serialize them somehow (and just make your app assert the type you are using can hold a certain minimum value). |
||||
|
||||
![]() swiftcoder Member since: 7/3/2003 From: Boston, MA, United States |
||||
|
|
||||
| On most unix, but sadly missing from MSVC, is the header <stdint.h>, which gives you access to explicit integer sizes. However, on common 64-bit desktop systems (i.e. Windows, Mac and many Linux), int remains a 32-bit type, short a 16-bit type, and char a 8-bit type. Tristam MacDonald - swiftcoding |
||||
|
||||
![]() Ftn Member since: 2/17/2004 From: Helsinki, Finland |
||||
|
|
||||
| Boost has cstdint typedef's useful for writing portable code that requires certain integer widths. |
||||
|
||||
![]() Evil Steve Moderator Member since: 6/30/2003 From: Edinburgh, United Kingdom |
||||
|
|
||||
| On my system (XP 64, Visual Studio 2005, 64-bit build): sizeof(char) == 1 sizeof(short) == 2 sizeof(int) == 4 sizeof(long) == 8 sizeof(float) == 4 sizeof(double) == 8 Steve Macpherson DirectX MVP and Programmer, Firebrand Games |
||||
|
||||
![]() Rewdew Member since: 2/8/2009 From: Reims, France |
||||
|
|
||||
| Main difference is for sizeof(T *) which should be 8 on all the 64-bit systems... |
||||
|
||||
![]() Guthur Member since: 1/15/2006 |
||||
|
|
||||
| The only guarantee C++ makes is that 1 char == 1 byte and then the other >= ones, but the the size of a byte is system dependant. The only time I can think of where this would be an issue for you is that if you wanted to communicate between 2 completely different platforms that had very thin network layers. But I would imagine the most likely systems you are really going to come across or communicate with will have some flavour of mass market OS which will have nice robust network layers to resolve this case for you, in other cases you will be running on whatever system so it should be all dandy as C++ just says be a byte, whatever a byte is is up to the system. I suppose if you want to do alot of bit shifting it would be also quite irksome. Char encoding is where you run into all this different size stuff as well, rather annoying sometimes. |
||||
|
||||
![]() Icon Member since: 1/18/2008 From: Malaga, Spain |
||||
|
|
||||
| On my machine (XP_64, VS2005, 64bit build) sizeof(long) == 4 Iirc, sizeof(long) == 8 when using the LP64 data model (Linux?). Again iirc, Windows uses LLP64. |
||||
|
||||
![]() Evil Steve Moderator Member since: 6/30/2003 From: Edinburgh, United Kingdom |
||||
|
|
||||
Quote:Ah, good point - I stand corrected. I was going from memory rather than testing it. Results from an actual test: Quote: Steve Macpherson DirectX MVP and Programmer, Firebrand Games |
||||
|
||||
![]() magic_man Member since: 2/1/2009 |
||||||||
|
|
||||||||
Quote: This is not totally correct. C++ is a near super set of C and includes limits.h which is defined in the C standard as having minimum sizes which are as stated here and "5.2.4.2.1 Sizes of integer types <limits.h>" are: Quote: Note long long is currently a C type yet not a C++ so we can just disregard that type. The C++ standard includes limits calling it climits and therefore abides by these guarantees which is expressed in C2.4 and 18.2.1.2 Quote: Further as Icon stated there is also other methods of guaranteeing the sizes of types based on the model being used, the list of which includes LP32, ILP32, ILP64, LLP64 and LP64. See this page for information about each model. So to answer the OP's questions Quote: It is dependant on the model being used. Quote: Windows 64 adheres to the LLP64 model, Quote: If the 32bit systems was windows then yes they would be the same(see 64 bit link above which states the models.) Quote: If you need sizes of types to be correct across different models and os's then you need to use fixed size types which has already been commented on in this thread. [edit] In addition there is an article which tackles some of these points and more related to porting to 64 bit systems which is hosted on this site. You can find the article entitled "20 issues of porting C++ code on the 64-bit platform" here. [Edited by - magic_man on March 4, 2009 6:46:52 AM] |
||||||||
|
||||||||
![]() Guthur Member since: 1/15/2006 |
||||
|
|
||||
| I stand corrected :), nice info to. |
||||
|
||||
![]() Imgelling Member since: 2/17/2007 From: Lexington, KY, United States |
||||
|
|
||||
| Sorry I couldn't reply earlier. Thanks for everyone's help! |
||||
|
||||
![]() Promit Moderator - Graphics Programming and Theory Member since: 7/29/2001 From: Baltimore, MD, United States |
||||
|
|
||||
| Here's what I know (applies to x86-32 and x86-64 only): long long is 64 bits on both GCC and VC8+ regardless. long is 64 bits on GCC x64 and 32 bits on VC8+ x64. int is 32 bits on both regardless. short is 16 bits on both regardless. |
||||
|
||||
All times are ET (US)![]() |
Last Thread Next Thread ![]() |
|