Parametrized new () expects an "identifier"
I found the following code in an old document (1977!) And needs to run it. However, I get the following error from FreePascal (2.6.4, Win64) on the first "new" one:
(14, 9) Fatal: Syntax error, "identifier" expected but "TRUE" found
According to this ('new') and this ('record') it should work, but it doesn't. Any suggestions?
program prog(input, output);
type ptr = ^node;
node = record position: 1 .. 512; fathers: array [0.. 4] of ptr;
case (* internal: *) boolean of
true: (ub: (minus, undef, plus);
left, right: 0..5;
rank: 0.. 4);
false: (present: boolean; pred, succ: ptr);
end;
procedure initialize(level: integer);
var v: ptr;
begin if level > 0 then
new(v,true)
else
new(v,false);
end
source to share
In your code, you call a New
procedure that passes booleans into a second parameter, which signals the Free Pascal compiler to select this overload:
procedure New(var P: Pointer; Cons: TProcedure);
which is used to highlight objects, where the second parameter is Cons
used to pass the object constructor method. Therefore, in this case, the compiler was expecting a method and not a boolean.
Since you are not allocating objects other than records, you can call the procedure New
just like this:
New(v);
source to share
The code you are using is probably ISO Pascal. FPC 2.6.4 cannot handle this construct. FPC from svn trunk aka FPC 2.7.1 can when compiled using command line -Miso
. Boolean values passed to new
get a value as soon as you don't comment out a character internal
. When this so-called tag field is present, it is initialized with the value passed to new
.
source to share