summaryrefslogtreecommitdiff
path: root/fpcsrc/tests/webtbs/tw8513.pp
blob: 8a37d84c0d22aab4157177d90b435a3b7561ee76 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
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.