View Issue Details

IDProjectCategoryView StatusLast Update
0037822FPCCompilerpublic2020-10-13 21:50
Reporterravi dion Assigned To 
PrioritynormalSeverityminorReproducibilityalways
Status feedbackResolutionopen 
Product Version3.3.1 
Summary0037822: Alignment Attribute
DescriptionSince FPC supports attributes it'd be nice to control alignment through it
Steps To Reproduce{$A4}
type
  TMyRecordA = record
    x: Integer;
    y: Int64;
  end;

  TMyRecordB = record
    x: Integer;
    [Align(8)]
    y: Int64;
  end;
var
  a: TMyRecordA;
  b: TMyRecordB;
  offset: Integer;
begin
  offset := PByte(@a.y) - PByte(@a);
  Writeln(SizeOf(a));
  Writeln(offset);
  offset := PByte(@b.y) - PByte(@b);
  Writeln(SizeOf(b));
  Writeln(offset);
Additional Informationhttps://wiert.me/2020/09/25/delphi-the-use-of-alignattribute-indicate-the-alignment-of-a-field/
TagsNo tags attached.
Fixed in Revision
FPCOldBugId
FPCTarget-
Attached Files

Activities

Sven Barth

2020-09-27 11:49

manager   ~0125896

Last edited: 2020-09-27 11:49

View 2 revisions

FPC currently only supports custom attributes for types and published properties, for anything more support for extended RTTI is required first.

Florian

2020-10-03 10:30

administrator   ~0126051

What is the use case of this? IMO it makes no sense: if y shall be 8 byte aligned, TMyRecordB must be as well, so just setting the aligment to 8 before the TMyRecordB declaration is enough?

Sven Barth

2020-10-03 11:28

manager   ~0126054

Probably to avoid the need to add either manual paddings when using packed or to have a more granular control. E.g. for reading from a binary file it's not necessary that the record itself is correctly aligned, only that the fields are.

ravi dion

2020-10-03 21:22

reporter   ~0126068

Oh didn't know that extended RTTI is needed. Any ETA for this feature?

Florian

2020-10-04 19:21

administrator   ~0126087

> Probably to avoid the need to add either manual paddings when using packed or to have a more granular control. E.g. for reading from a binary file it's not necessary that the record itself is correctly aligned, only that the fields are.

I think this is not a good enough reason for this ugly construct :) It would be probably more confusing. If binary reading is required, packed records with dummy fields are imo the way to go.

ravi dion

2020-10-13 12:46

reporter   ~0126281

If you like it or not, it's needed for Delphi compatibility. ;-)

Florian

2020-10-13 20:03

administrator   ~0126285

We do not support each Delphi construct anymore, see e.g. inline variable declarations.

Issue History

Date Modified Username Field Change
2020-09-27 00:02 ravi dion New Issue
2020-09-27 11:49 Sven Barth Note Added: 0125896
2020-09-27 11:49 Sven Barth Note Edited: 0125896 View Revisions
2020-10-03 10:30 Florian Note Added: 0126051
2020-10-03 10:30 Florian Status new => feedback
2020-10-03 10:30 Florian FPCTarget => -
2020-10-03 11:28 Sven Barth Note Added: 0126054
2020-10-03 21:22 ravi dion Note Added: 0126068
2020-10-03 21:22 ravi dion Status feedback => new
2020-10-04 19:21 Florian Assigned To => Florian
2020-10-04 19:21 Florian Status new => resolved
2020-10-04 19:21 Florian Resolution open => won't fix
2020-10-04 19:21 Florian Note Added: 0126087
2020-10-13 12:46 ravi dion Status resolved => feedback
2020-10-13 12:46 ravi dion Resolution won't fix => open
2020-10-13 12:46 ravi dion Note Added: 0126281
2020-10-13 20:03 Florian Note Added: 0126285
2020-10-13 21:50 Florian Assigned To Florian =>