tags:

views:

72

answers:

2

I know that size of various data types can change depending on which system I am on. I use XP 32bits, and using the sizeof() operator in C++, it seems like long double is 12 bytes, and double is 8.

However, most major sources states that long double is 8 bytes, and the range is therefore the same as a double.

How come I have 12 bytes? If long double is indeed 12 bytes, doesn't this extends the range of value also? Or the long signature is only used (the compiler figures) when the value exceed the range of a double, and thus, extends beyond 8 bytes?

Thank you.

+6  A: 

Quoting from Wikipedia: "On the x86 architecture, most compilers implement long double as the 80-bit extended precision type supported by that hardware (sometimes stored as 12 or 16 bytes to maintain data structure alignment)". and "Compilers may also use long double for a 128-bit quadruple precision format, which is currently implemented in software".

In other words, yes, a long double may be able to store a larger range of values than a double. But it's completely up to the compiler.

Borealid
Data types depends heavily on the architecture you're developing for.
karlphillip
It also depends on compiler options. The 80-bit type can be explicitly disabled on almost every x86 compiler.
greyfade
@karlphillip, @greyfade: Yes, I just meant "up to the compiler" in the sense that it decides how to store your data. Obviously it's limited to what is available on the platform, and of course the compiler can choose to allow a user override.
Borealid
thank you for your reply!
JohnWong
A: 

The standard byte sizes for numbers are the guaranteed minimum sizes across all platforms. They may be larger on some systems, but they will never be smaller.

scott77777