Pascal Viandier wrote:
I have a question about field's alignment in GNU Pascal records on different platforms.
So my question is: How come the difference in alignment of Rec1 in Rec2 between Sparc and Linux?
The default alignment and padding are defined by the ABI of the target platform, the compiler must follow the ABI.
I can manage this with 'dummy' fields in record declarations - enclosed in {$ifdef }...{$endif} but I would like to be sure to understand how the alignment is done in order to avoid recurrent problems on this matter.
Instead, try --maximum-field-alignment=n where n is expressed in bits (e.g. 8, 16, 32, 64). On i386-apple-darwin I get
[p17:~/gpc/testgpc/adriaan] adriaan% gpc viander01.pas --maximum-field-alignment=8 [p17:~/gpc/testgpc/adriaan] adriaan% ./a.out Offset of Str11 in Rec2 : 0 Offset of Rec1 in Rec2 : 20 Offset of Str16 in Rec2 : 20 Offset of R in Rec2 : 48
Offset of Str11 in Rec3 : 0 Offset of Str16 in Rec3 : 20 Offset of R in Rec3 : 48
[p17:~/gpc/testgpc/adriaan] adriaan% gpc viander01.pas --maximum-field-alignment=64 [p17:~/gpc/testgpc/adriaan] adriaan% ./a.out Offset of Str11 in Rec2 : 0 Offset of Rec1 in Rec2 : 24 Offset of Str16 in Rec2 : 24 Offset of R in Rec2 : 56
Offset of Str11 in Rec3 : 0 Offset of Str16 in Rec3 : 20 Offset of R in Rec3 : 48
You can also use it as a compiler directive in source code, e.g. {$maximum-field-alignment=16}.
Regards,
Adriaan van Os