If there are alignment issues,
absolute will have the same alignment issues and more side effects when the alignment is not byte aligned or natural alignment.
But you can always use
packed records,or adjust the alignment with the align directive.
The cast is pretty safe in this case, as long as both record types are compiled with the same alignment.
If you want truly predictable alignment, use packed records.
type
T2dPoint = packed record
..
To complicate matters you can use
{$packrecords 1/2/4/8/C} or
{$a1/2/4/8} but note that that
will pack just all records that are NOT declared as packed to the specified alignment.
A record declared specifically as packed will always be in $A1 alignment, i.e. byte aligned. Has to do with File IO reasons: you don't want to store and read slackspace.
See
http://freepascal.org/docs-html/current/prog/progsu60.html#x67-660001.2.60 but that is not very clear about the above.
Predictable consistency is only achieved by a declaration of a
packed record which is always byte aligned, whatever the {$packrecords} setting may be.
Demo:
program packdemo;
{$ifdef fpc}{$mode delphi}{$H+}{$endif}
{$packrecords 2}
type
Record_a = packed record
a:byte;
b:integer;
end;
Record_b = record
a:byte;
b:integer;
end;
begin
writeln(sizeOf(Record_a));//should be 5, byte aligned, ignores packrecords
writeln(sizeOf(Record_b));//should be 6, word aligned, adheres to packrecords
end.
Note that
absolute has its own uses, many of which are life savers..
One example is that FPC since 3.0 ignores the bit pattern of an integer when cast to a single, but returns the closest single value... (imo stupidest thing ever that the devs decided for 3.0, breaks loads of C translated code)
http://wiki.freepascal.org/User_Changes_3.0#Casting_integer_variables_to_floating_pointIf you want C like behavior you can declare an single variable as absolute to the integer variable to obtain its bit pattern representation,
For absolute to work on a record that is not packed, you will need to know its alignment beforehand, as the above demo also implies.
Also note that many of the most experienced programmers do not realize the above matters about packed....