Just making sure.
When you write 64 bit software:
short is 16 bits
int is 32 bits
long is 64 bits right?
add on please..
64 Bit C Datatypes
- crazygray1
- Member
- Posts: 168
- Joined: Thu Nov 22, 2007 7:18 pm
- Location: USA,Hawaii,Honolulu(Seriously)
- Brynet-Inc
- Member
- Posts: 2426
- Joined: Tue Oct 17, 2006 9:29 pm
- Libera.chat IRC: brynet
- Location: Canada
- Contact:
Re: 64 Bit C Datatypes
Wrong.crazygray1 wrote:Just making sure.
When you write 64 bit software:
short is 16 bits
int is 32 bits
long is 64 bits right?
add on please..
On 32bit systems:
char is 8 bits..
short is 16bits..
int is typically 32bits.. (Never assume int is 32bits.. it's not always.)
long is 32bits..
"long long" would be a 64bit type..
If you're on a 64bit system, you should be aware of the "data model" being used by the operating system.
http://en.wikipedia.org/wiki/64bit#64-bit_data_models
I typically advice C programmers to use C99 types whenever possible.. (Normally found in stdint.h)
int8_t/uint8_t
int16_t/uint16_t
int32_t/uint32_t
int64_t/uint64_t
Hopefully, The OS you're using will have these types setup properly..
Have fun...
Last edited by Brynet-Inc on Sun Jan 06, 2008 10:32 pm, edited 1 time in total.
On my 64bit setup:
yields:
So, on 64bit machines you would be correct. (Albeit unportable.)
Code: Select all
printf("%li %li %li %li\n", sizeof(char), sizeof(short), sizeof(int), sizeof(long));
Code: Select all
1 2 4 8
C8H10N4O2 | #446691 | Trust the nodes.
- Brynet-Inc
- Member
- Posts: 2426
- Joined: Tue Oct 17, 2006 9:29 pm
- Libera.chat IRC: brynet
- Location: Canada
- Contact:
Right, on many 64bit Unix systems that's correct.. although...Alboin wrote:So, on 64bit machines you would be correct. (Albeit unportable.)
64bit Windows would have returned:
1 2 4 4
Only pointers and long long are 64bit.. LLP64 data model.
I don't know any ILP64 or SILP64 implementors.. but the latter uses 64bits for short! hah!
With regret and some irritation I have to inform you that C did not, does not, and never will make any definition of which datatype will be which width on platform xyz.
sizeof( char ) = 1
sizeof( short ) >= sizeof( char )
sizeof( int ) >= sizeof( short )
sizeof( long ) >= sizeof( int )
sizeof( long long ) >= sizeof( long )
For everything else, use the typedef's in <stdint.h>. Assumptions like "on my machine..." will only shoot you in the foot.
sizeof( char ) = 1
sizeof( short ) >= sizeof( char )
sizeof( int ) >= sizeof( short )
sizeof( long ) >= sizeof( int )
sizeof( long long ) >= sizeof( long )
For everything else, use the typedef's in <stdint.h>. Assumptions like "on my machine..." will only shoot you in the foot.
Every good solution is obvious once you've found it.
- crazygray1
- Member
- Posts: 168
- Joined: Thu Nov 22, 2007 7:18 pm
- Location: USA,Hawaii,Honolulu(Seriously)