On Thursday 18 June 2009 08:51:13 Vincent Snijders wrote: > Graeme Geldenhuys schreef: > > Hi, > > > > Recently I learned that you can have writeable typed constants. That > > sounds rather like an oxymoron to my. Writeable constants make no sense, > > is that then simply a variable? What is the use of a writeable typed > > constant? > > Backwards compatibility with turbo pascal, which lacked initialized > variables and writable constants were the alternative.
Is this likely to be dropped in future versions of FPC? I have taken advantage of this in functions where a static variable would be used in other languages like C. In the following example, the typed constant Count is initialised only once when Test() is first called and thereafter retains its value between function calls. procedure Test(); const Count : Cardinal = 1; begin Writeln('The value of Count is now ', Count); Inc(Count); end; var i : LongInt; begin for i := 1 to 10 do Test(); end. will yield; The value of Count is now 1 . . The value of Count is now 10 Although a writable constant makes no sense, it come in handy and is a cool feature to have. Perhaps a construct derived from this feature can be added to FPC? Regards, Nino _______________________________________________ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-pascal