Prof A Olowofoyeku (The African Chief) wrote:
On 7 Feb 2004 at 21:25, Peter Norton wrote:
The Chief wrote:
Please send an example of such code.
<code snippet> bmpinfo = record (*BMP header*)
[...] You will need to pack the record (bearing in mind CBF's warning about portability, etc.). Using "packed" may not always be portable. The following solution may or may not be portable (Frank can tell us):
type {$ifdef __GPC__}{$pack-struct, maximum-field-alignment 8} {$endif} bmpinfo = record (*BMP header*) b1, b2 : char; size : integer; reserved : integer; offset : integer; headersize : integer; width : integer; height : integer; planes : shortword; bpp : shortword; compression : integer; comprsize : integer; horresolution : integer; verresolution : integer; usedcolors : integer; importantcol : integer; end; {$ifdef __GPC__}{$no-pack-struct, maximum-field-alignment 0}{$endif}
To be portable, you cannot use types like `Integer' and `ShortWord' which can have different sizes. You can define your own types to be `Integer attribute (Size = 32)', `Cardinal attribute (Size = 16)' etc. Also you have to do explicit endianness conversions (see `ConvertFromLittleEndian' etc. in gpc.pas).
Frank