Should the different variants in a variant record overlay in the same
memory?
Previous Pascals I have used have guaranteed this, and I've got
low-level code that relies on this.
The simple example below shows that this is not true for GPC - the version
as reported by gpc -v is:
Reading specs from /usr/local/lib/gcc-lib/i586-pc-linux-gnu/2.95.2/specs
gpc version 19991030, based on 2.95.2 19991024 (release)
The output from the program is:
addr of i is: -1073742896
addr of s is: -1073742760
addr of ic is: -1073742668
program daj15(input,output);
type trec = record
case integer of
1:(i:array [1..34] of integer);
2:(s:string(80));
3:(ic:packed array[0..79] of char);
end;
var r:trec;
procedure sub(r:trec);
begin
writeln('addr of i is: ',integer(addr(r.i)):1);
writeln('addr of s is: ',integer(addr(r.s)):1);
writeln('addr of ic is: ',integer(addr(r.ic)):1);
end;
begin
sub(r);
end.
If the string s is removed from the record, then the same address is
reported for i and ic.
(I know the variants are not the same length, and they are intended
not to be.)
--
David James
mailto:david@tcs01.demon.co.uk