Skip to main content
gamedev.net
🔒 Locked

Confusing data types in c++

Started by TechnoCore 6 replies 450+ views
Original Post
TechnoCore
TechnoCore
I want to know how many bits certain data types take up: Could someone please render some light for me in this forrest of data types ? Im using vc 7.0, some of these differ from different systems, right ? single float double int long dword LONGLONG LARGE_INTEGER Thanks for any help (Are there more data-types i should be aware of for numbers & floats ?)
//TechnoCore
khalligan
khalligan
int, long, float generally are all 32 bits,
short is generally 16 bits.

Do a sizeof(type)
to find the exact size, they are highly dependent on the machine they are compiled on, they always are guaranteed to be at least a specific size, and may be larger, (ie. an int is guaranteed to be at least 16-bits)... specified in C Spec I think

Qw3r7yU10p!
Qw3r7yU10p!
single?

depending upon the platform they may have different sizes.

The documentation should tell you.

Also you could write a program to tell you the size of types using the sizeof operator. Look it up.

[edited by - petewood on March 30, 2004 7:41:57 AM]
TechnoCore
TechnoCore
Thanks guys, i''ll do the sizeof thing.
I was reading from the time stamp counter and got weird results
//TechnoCore
amag
amag
sizeof(char) is guaranteed to always return 1. Actually int is not specified to have at least 16 bits. IIRC on original Gameboy int is only 8 bits.

[edited by - amag on March 30, 2004 7:57:26 AM]
_the_phantom_
_the_phantom_
correct, from 3.9.1 of the spec (para-phrased)

1) a char must be able to store any member of the implimentation''s basic character set

2) there are 4 signed integer types, "unsigned char", "short int", "int" and "long int". In this list, each type provides at least as much storeage as the one before it.

Which is why an int can be 8bits on something like the gameboy.
JohnBolton
JohnBolton
Strictly speaking, the sizes are up to the compiler. Different compilers (and even different versions of the same compiler) for the same platform might use different sizes for the same type.
John BoltonLocomotive Games (THQ)Current Project: Destroy All Humans (Wii). IN STORES NOW!
amag
amag
quote:
Strictly speaking, the sizes are up to the compiler. Different compilers (and even different versions of the same compiler) for the same platform might use different sizes for the same type.

Ok, sorry for not speaking strictly, you are correct. However I don't remember which compiler I used when programming for the Gameboy, since it was four score and seven years ago. Probably some version of LCC, but since the Z80 is an 8-bit processor it's quite likely that any other C-compiler for the Gameboy also stores int:s as 8 bits.

[edited by - amag on March 30, 2004 6:14:41 PM]

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.