Mail Archives: djgpp/1996/09/19/03:07:15
On 18 Sep 1996, S. Mikecin wrote:
> DJGPP has three floating-point (FP) data types: float (4 bytes), double (8
> bytes) and long double (12 bytes). Since x86 FPU supports ONLY
> 32-bit,64-bit and 80-bit floating-point numbers (and also 64-bit integer
> numbers), I see no reason why long double is of size 12, and not 10 bytes!
> It has nothing to do with alignment because it is also 12, even when I use
> #pragma pack(1). Is there any explanation?
It *is* for alignment reasons. GCC wants long double to be aligned on
DWORD boundaries. Since you can create arrays of long double, this
implies padding long doubles to 12 bytes, and `sizeof' must know this, or
else pointer arithmetics won't work. Let's say you have the following
code:
long double *pld = ldbl_array;
while (*pld != 0.)
pld += 5;
The line "pld += 5;" is translated by the compiler like this:
pld = (long double *)( (char *)pld + 5*sizeof(long double) );
Now you can understand why `sizeof' must be consistent with the alignment
of the array elements (the same goes for structs which are sometimes
padded at the end).
- Raw text -