About constants in Turbo Pascal 7

In Turbo Pascal (TP7), const x = 1 is immutable (a true constant), while const x: integer = 1 is a variable in disguise

Example snippet:

const
  TestConst1 = 100;  { this is immutable }
  TestConst2: integer = 200;  { this is a variable in disguise }

begin
  writeln(TestConst1);
  writeln(TestConst2);

  { testconst1 := 200; }  { This causes an "error in statement" error}
  testconst2 := 300;

  writeln(TestConst1);
  writeln(TestConst2);

  readln
end.

But the behaviour is still expected like in Free Pascal: the compiler picks up the smallest type that can fit the value in, and makes it immutable

So,

const
  MaxSize = 100;

would fit in a Byte range and is immutable, while on the other hand,

const
  Counter: integer = 0;

is basically an initialised variable

This entry was posted in Turbo Pascal 7 and tagged , , . Bookmark the permalink.