Question about fields alignment
Waldek Hebisch
hebisch at math.uni.wroc.pl
Fri Sep 21 22:25:38 CEST 2007
Pascal Viandier wrote:
> Hi,
>
> I have a question about field's alignment in GNU Pascal records on
> different platforms.
>
> Consider the sample program below:
>
> Program offsets;
> Type
> Rec1_t = Record
> Str16 : String(16);
> R : Real;
> End;
> Rec2_t = Record
> Str11 : String(11);
> Rec1 : Rec1_t;
> End;
> Rec3_t = Record
> Str11 : String(11);
> Str16 : String(16);
> R : Real;
> End;
<snip>
> This looks good to me. Rec1 and Rec3 map on each other.
> How come the difference in alignment of Rec1 in Rec2 between Sparc and
> Linux?
> I know that Real data is aligned on 8 bytes boundaries on Sparc
> platforms but why is the address of Rec1 aligned on 8 bytes instead of
> 4?
Typical rule is that a record requires bigger or equal alignment as
each of its components. So Rec1 needs at least Real alignment.
> So the two records (Rec2 and Rec3) containing the same data are of
> different sizes and do not map anymore. This causes some trouble in my
> programs since this kind of data structures are passed back and forth to
> C code, in order to interface with a database engine.
Hmm, GNU Pacal uses the same rules as C, so C structures corresponding
to Rec2 and Rec3 also does not mach -- at most one can be correct.
--
Waldek Hebisch
hebisch at math.uni.wroc.pl
More information about the Gpc
mailing list