Archived

This topic is now archived and is closed to further replies.

Confusing data types in c++

This topic is 5006 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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 ?)

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites