[fpc-devel]procedural variables problems (1.1 branch)

Pavel V. Ozerski pavel at insect.mail.iephb.ru
Tue Dec 17 11:39:38 CET 2002


Hello all,
May be, my snapshot is slightly outdated but these problems may be not
fixed yet. Therefore I would report about them. May be, some of these
problems are already known.


1) variables absolute to procedural variables are not supported
sometimes. Compiler finds an error only if this procedural variable uses no
parameters (but can be a procedure or a function) or if Delphi- or
TP-compatible compilation mode is used: "Error: absolute
can only be associated with a var or const" and in second case
additionally "Error: Wrong number of parameters specified" if variable
has a parameter list, otherwise all is OK. That breaks BP/Delphi
compatibility and creates some real problems for programming. Examples:

var
 x:function:longint;
 y:pointer absolute x;
begin
end.

{$mode Delphi}
var
 x:function(x:longint):longint;
 y:pointer absolute x;
begin
end.



2) How to access of address of procedural variable in TP- or
Delphi-compatible mode? This sample works correctly after compilation
by Delphi 6 but cannot be compiled by FPC compiler:

{$ifdef FPC}
{$mode Delphi}
{$endif}
{$APPTYPE CONSOLE}
var
 x:function(x:longint):longint;
 y:pointer absolute x;
 z,w,v:pointer;
begin
 z:=@@x;
 w:=addr(@x);
 v:=@(addr(x));
 writeln(longint(y),' ',longint(z),' ',longint(w),' ',longint(v));
end.

I explored compiler sources a little and found that a new token
DOUBLEADDR @@ is introduced although it doesn't work now. But this sample
demonstrates also that this way seems to be wrong, IMHO, because all
combinations of @ and addr() are supported in Delphi here.

-- 
Sincerely,
 Pavel                            mailto:pavel at insect.mail.iephb.ru







More information about the fpc-devel mailing list