Date: Thu, 19 Sep 1996 08:49:30 +0200 (IST) From: Eli Zaretskii To: sime AT fly DOT cc DOT etf DOT hr Cc: djgpp AT delorie DOT com Subject: Re: sizeof(long double)==12 In-Reply-To: <51om9k$cof@bagan.srce.hr> Message-Id: Mime-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII 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).