123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- type
- TMyType = cardinal;
- tr = record
- a,b,c,d: byte;
- end;
- procedure t(var l: cardinal);
- begin
- if (l <> $cafebabe) then
- halt(4);
- l := $c001d00d;
- end;
- var
- Item: TMyType;
- ItemAsByte: byte absolute Item;
- r: tr;
- b: byte absolute r.b;
- l: cardinal;
- labs: cardinal absolute l;
- begin
- { Of course I understand fully that this code is bad
- (unless you really want to read the 1st byte of 4-byte LongInt
- type, messing with endianess problems).
- In real code, I accessed ItemAsByte only when
- SizeOf(TMyType) = 1 (the code is
- used like a simple template, so it must work with any
- TMyType, and the case when SizeOf(TMyType) = 1 uses some
- specially optimized versions (e.g. FillChar(..., ItemAsByte)
- can be used in this case to fill the array of TMyType). }
- {$ifdef FPC_BIG_ENDIAN}
- item:=$deadbeef;
- {$else}
- item:=$efbeadde;
- {$endif}
- if (itemasbyte <> $de) then
- halt(1);
- r.a := $de;
- r.b := $ad;
- r.c := $be;
- r.d := $ef;
- if (b <> $ad) then
- halt(2);
- l := $cafebabe;
- t(labs);
- if (l <> $c001d00d) then
- halt(6);
- end.
|