Define it as such:
type TValue = packed record
case Kind : cardinal of
valueShortCard : ( ValShortCard : byte );
valueLongReal : ( ValLongReal : double );
end;
Here, sizeof(TValue)=12
, as you expected.
Adding packed record
force no alignment to be generated. If there is no alignment, double
will be aligned on 8 bytes boundaries, so Kind
will use 8 bytes instead of 4, and valueLongReal
also, therefore, sizeof(TValue)=8+8=16
in your case.
Note that under AMD/Intel, you should better align your double
variables for performance reasons. On ARM, alignment is required.
Note also that variable records alignment changed with Delphi XE3 AFAIR in respect to previous versions.