17.03.2015 12:45, [email protected] wrote:
> i assign it to whole record not for member by member
So, you don't know what values should be in what member ?
> but how offsets can hange any in this representation?
It show us exactly how compiler works
> I should do for one integer "word" alignment
> but for smallint dword
> and for next integer different alignment then for first integer?
> I should gues this or are some rules? Somewhere in FBSource - that after
> smallint another integer+WordBool should be aligned whith DWord?
Rules as simple - for simple types alignment is a sizeof this type.
> think about this simplified record declaration - how will you declare this?
>
> GenRowsInMessage = record
> iValue: Integer;
> iValueNull: WordBool;
> sValue: SmallInt;
> sValueNull: WordBool;
> iValue2: Integer;
> iValue2Null: WordBool;
> end
Alignments (offsets) of members within record should be:
member data type sizeof datatype offset
iValue Integer 4 0
iValueNull WordBool 2 4
sValue SmallInt 2 6
sValueNull WordBool 2 8
iValue2 Integer 4 12
iValue2Null WordBool 2 16
but only if record is *not* packed and declared with {$A+}.
Note, iValue2 have offset 12, not 10 !
BTW, Delphi docs is not fully consistent, see:
1.
http://docwiki.embarcadero.com/RADStudio/XE7/en/Internal_Data_Formats#Record_Types
When a record type is declared in the {$A+} state (the default), and when the
declaration
does not include a packed modifier, the type is an unpacked record type, and
the fields of
the record are aligned for efficient access by the CPU, and according to the
platform. *The
alignment is controlled by the type of each field. Every data type has an
inherent alignment,
which is automatically computed by the compiler.* The alignment can be 1, 2, 4,
or 8, and
represents the byte boundary on which a value of the type must be stored in
order to provide
the most efficient access.
This is how C++ compiler works and what we are expected. But
2. http://docwiki.embarcadero.com/RADStudio/XE7/en/Align_fields_%28Delphi%29
The $A directive controls the maximum alignment used by the compiler when
introducing padding
to align a field.
...
In the {$A8} or {$A+} state, fields in record types that are declared without
the packed
modifier and fields in class structures are aligned on quadword boundaries.
I.e. it is not consistent with link (1). I hope, that {$A+} and {$A8} is not
the same and
think you should try {$A+} not leaving "default" value
Regards,
Vlad
------------------------------------------------------------------------------
Dive into the World of Parallel Programming The Go Parallel Website, sponsored
by Intel and developed in partnership with Slashdot Media, is your hub for all
things parallel software development, from weekly thought leadership blogs to
news, videos, case studies, tutorials and more. Take a look and join the
conversation now. http://goparallel.sourceforge.net/
Firebird-Devel mailing list, web interface at
https://lists.sourceforge.net/lists/listinfo/firebird-devel