[fpc-pascal]typed constants

Michael.VanCanneyt at Wisa.be Michael.VanCanneyt at Wisa.be
Thu Jan 2 13:00:54 CET 2003


Hi,

This is a follow-up on the 'typed local const' issue:

Peter Vreman implemented support for initialized local variables
in the 1.1 version of the compiler.

This means that:

1. Local typed constants retain their current behaviour
   (Compatible with Delphi and TP):

   Local typed constants are initialized at program startup.
   If they are modified during the execution of the procedure
   in which they are defined, they will retain this modified
   value across calls to this procedure.

   This is true in both 1.1 and 1.0 version of the compiler.

   Consider the following program :

   program tinivar;

   procedure p1;
   Const
     a : integer = 1;
   begin
     writeln(a);
     if a<>1 then
       halt(1);
     inc(a);
   end;

   begin
     p1;
     p1;
   end.

   This will print
   1
   2
   and exits with code 1

   This is compatible with Delphi/TP.

2. Initialized local variables will be initialized on procedure entry
   when compiled using version 1.1 of the compiler.
   Programs compiled with version 1.0 of the compiler retain their current
   behaviour, as in the case of a 'local typed constant'.

   Consider the following program:

   program tinivar;

   procedure p1;
   Var
     a : integer = 1;
   begin
     writeln(a);
     if a<>1 then
       halt(1);
     inc(a);
   end;

   begin
     p1;
     p1;
   end.

   Compiled with version 1.1, this will print
   1
   1
   and exits with code 0

   Compiled with version 1.0, this will do the same as if 'a' was
   a local typed constant.

   Note that this behaviour is does not conflict with Delphi,
   since neither TP nor Delphi allow this.

There are no plans to back-port this to version 1.0 of the compiler,
because the compiler internals are too different for this to be feasible in
a reasonable period.

People that want initialized variables will have to switch to
the 1.1 compiler, snapshots with this new behaviour should become
availabe soon. The patch for this is already in CVS.

Michael.





More information about the fpc-pascal mailing list