[fpc-devel] Aligned array feature

Karoly Balogh charlie at scenergy.dfmk.hu
Wed Apr 13 00:27:02 CEST 2022


On Tue, 12 Apr 2022, J. Gareth Moreton via fpc-devel wrote:

> To complement aligned records, I'm trying out an implementation of
> aligned records.  Like how you might declare an aligned record as follows:
> type AlignedVector = packed record
>      X, Y: Double;
> end align 16;

Is this "aligned records" a new language feature already implemented, or
it's only being proposed? What is the result of the above syntax?

It's very confusing that it's both a "packed" and an "aligned" record.

> Of course, that assumes such alignment support is okay in the eyes of
> the core team (I'll need to double-check what Delphi supports so it's
> enabled or disabled as appropriate under $MODE DELPHI).

Well, it depends on what "align 16" would do in these cases. Only change
the alignment between the fields/elements of the record and array? Or try
to guarantee the alignment of the array and the record itself? The later
might be extremely tricky to provide in a reliable and platform
independent way, as for global variables it might depend on the behavior
of linkers, OS loaders, and so on, and for heap variables it will depend
on the alignment the heap allocator supports. (Although we can extend the
heap allocator to support aligned allocations, but I'm still not a fan.)

And for just changing the alignment inside the array/record I think it's
too big of a syntax mess for too little benefit, which is just waiting for
abuse, and to be a source of hard to track down bugs.


More information about the fpc-devel mailing list