[fpc-devel]let Pascal stay Pascal

Jonas Maebe jonas at zeus.rug.ac.be
Fri Oct 27 13:31:39 CEST 2000


>var
>  a: Integer;
>
>function fact: Integer;
>begin
>  fact := 1;
>  if a <> 0 then
>  begin
>    Dec(a);
>    fact := (a+1)*fact;
>  end;
>end;
>
>begin
>  a := 3;
>  Writeln(fact);
>end.
>
>Of course it will write 6, and give the variable "a" value 0. Not in PPC.

It does if you use -So (Turbo Pascal compatibility mode) or -Sd (Delphi 
compatibility more). You indeed have to write

fact := (a+1)*fact();

if you want "fact" to be called again in FPC or Obj-FPC mode, which is 
indeed quite C-like. One reason is that we also introduced the C++ 
feature "function overloading". So if you have

***
type
  tf = function: longint;

procedure p(f: tf);
begin
end;

procedure p(l: longint);
begin
end;

function f: longint;
begin
  p(f); 
end;
***

then the compiler wouldn't know which overloaded procedure to call if f 
could also mean "call the function...

Use the -So (TP mode) command line switch if you want to disable all 
these features and as such the changes compared to TP.


Jonas




More information about the fpc-devel mailing list