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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
|
{$mode objfpc}
type
pshortstring=^shortstring;
tr = record
a,b,c,d,e: shortstring;
end;
ta = array[0..5] of shortstring;
tc = record
p: pointer;
end;
var
p,p2: pointer;
failed: boolean;
procedure error(err: longint);
begin
writeln('error near ',err);
failed:=true;
end;
function f1(p: pchar): tr;
begin
fillchar(result,sizeof(tr),0);
if (p^<>'x') then
error(1);
f1.a:=p^;
end;
function f2(var s: shortstring): tr;
begin
fillchar(result,sizeof(tr),0);
if (s<>'x') then
error(2);
f2.a:=s;
end;
function f3(const s: shortstring): tr;
begin
fillchar(result,sizeof(tr),0);
if (s<>'x') then
error(3);
f3.a:=s;
end;
function f4(const t: tr): tr;
begin
fillchar(result,sizeof(tr),0);
if (t.a<>'x') then
error(4);
f4:=t;
end;
function f5(p: pchar): ta;
begin
fillchar(result,sizeof(result),0);
if (p^<>'x') then
error(5);
result[3]:=p^;
end;
function f6(var s: shortstring): ta;
begin
fillchar(result,sizeof(result),0);
if (s<>'x') then
error(6);
result[3]:=s;
end;
function f7(const s: shortstring): ta;
begin
fillchar(result,sizeof(result),0);
if (s<>'x') then
error(7);
result[3]:=s;
end;
function f8(const t: ta): ta;
begin
fillchar(result,sizeof(result),0);
if (t[3]<>'x') then
error(8);
result:=t;
end;
procedure temp;
begin
if (pshortstring(p)^<>'x') then
error(9);
end;
function f9: tr;
begin
fillchar(result,sizeof(result),0);
temp;
result.a:='x';
end;
procedure temp2(var a);
begin
p2:=@a;
end;
function f10: tr;
begin
fillchar(result,sizeof(result),0);
if (pshortstring(p2)^<>'x') then
error(10);
result.a:='x';
end;
procedure testrec;
var
t: tr;
begin
t.a:='x';
t:=f1(@t.a[1]);
t:=f2(t.a);
t:=f3(t.a);
t:=f4(t);
p:=@t.a;
t:=f9;
end;
procedure testrec2;
var
t: tr;
begin
t.a:='x';
temp2(t.a);
t:=f10;
end;
procedure testarr;
var
t: ta;
begin
t[3]:='x';
t:=f5(@t[3][1]);
t:=f6(t[3]);
t:=f7(t[3]);
t:=f8(t);
end;
begin
testrec;
testrec2;
testarr;
if failed then
halt(1);
end.
|