[fpc-devel] C-block reference syntax (blocker for 3.2)

Michael Van Canneyt michael at freepascal.org
Thu Dec 12 17:14:32 CET 2019



On Thu, 12 Dec 2019, Sven Barth via fpc-devel wrote:

> Michael Van Canneyt <michael at freepascal.org> schrieb am Do., 12. Dez. 2019,
> 15:34:
>
>>> It was already mentioned, that the [] can be dropped if the array has
>>> *exactly one* element.
>>
>> Not sure what you mean here, but even if there is only 1 argument, today
>> the [] cannot be dropped:
>>
>> home:~> cat tf.pp
>> program tf;
>>
>> uses sysutils;
>>
>> begin
>>    writeln(Format('%s','huh?'));
>> end.
>> home:~> fpc tf.pp
>> tf.pp(6,29) Error: Incompatible type for arg no. 2: Got "Constant String",
>> expected "Array Of Const"
>> tf.pp(8) Fatal: There were 1 errors compiling module, stopping
>> Fatal: Compilation aborted
>> Error: /usr/local/bin/ppcx64 returned an error exitcode
>>
>
> For array of const it is not allowed, but any other open array parameter
> allows it.

Really, are you sure ? Since when is this allowed ?

Today's compiler:

araminta: ~ >fpc -S2 ti.pp
ti.pp(8,6) Error: Incompatible type for arg no. 1: Got "ShortInt", expected "{Open} Array Of LongInt"
ti.pp(9,4) Fatal: There were 1 errors compiling module, stopping
Fatal: Compilation aborted
Error: /usr/local/bin/ppcx64 returned an error exitcode
araminta: ~ >cat ti.pp

procedure a(b : array of integer);

begin
end;

begin
   A(1);
end.

Tested with 3.0.4 and trunk.

And I would not like it if this is allowed.
Imagine
procedure a(b : array of integer);
procedure a(b : integer);

The compiler would have no reason to prefer the second over the first when
it sees a(1);

Such ambiguities should not exist.

Michael.


More information about the fpc-devel mailing list