[comp.lang.pascal] Re Turbo typed constants

kirsch@braggvax.arpa (David Kirschbaum) (12/23/87)

(*
>From: JOSH%ILJCT.BITNET@CNUCE-VM.arpa
>To: info-pascal%brl.arpa.bitnet@wiscvm.wisc.edu
>
>  How constant are TP 3.0?'s typed constants when declared in procedures or
>functions? Are they like C's static variables, meaning that if I change such
>a variable, the next time I call that procedure I will remain with that value?
>  Global peace depends on this one...
>
>  Joshua Males
>
  Plenty constant.  Now if this were all it took to get global peace ...

David Kirschbaum
Toad Hall
kirsch@braggvax.ARPA
*)

PROCEDURE Bogus1;
  CONST
    bc1 : INTEGER = 0;
  BEGIN
    Writeln('In a Procedure:  local typed constant bc1 = ', bc1);
    bc1 := SUCC(bc1);
  END;

FUNCTION bogus2 : INTEGER;
  CONST
    bc2 : INTEGER = 0;
    BEGIN
      Bogus2 := bc2;
      bc2 := SUCC(bc2);
    END;

BEGIN
  Writeln('Demonstration of Turbo Pascal v3.0 "typed constants"');
  Writeln('within procedures and functions.');
  Writeln('Pause with ^S, Break with ^C.');
  Repeat
    Bogus1;
    Writeln('Using a Function:  local typed constant bc2 = ', bogus2);
  Until FALSE = TRUE;
END.

ari@well.UUCP (Ari Davidow) (12/25/87)

There is a bug in 3.0 re: typed constants and running an uncompiled
program.  Instead of resetting the definition of the constant at the
beginning of the program, Turbo may instead use the "current" value
(say, if the program is run more than once)--which may not be the
same as the original value.