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

Sven Barth pascaldragon at googlemail.com
Tue Dec 10 23:14:07 CET 2019


Ryan Joseph via fpc-devel <fpc-devel at lists.freepascal.org> schrieb am Di.,
10. Dez. 2019, 22:29:

>
>
> > On Dec 10, 2019, at 11:38 AM, Sven Barth via fpc-devel <
> fpc-devel at lists.freepascal.org> wrote:
> >
> > First of Object Pascal supports "array of const" which is safer due to a
> added type field for each entry.
> >
>
> From the users standpoint only real difference is the [] syntax and if the
> array of const is the last (or only) parameter the compiler could infer it
> right? i.e.
>
> DoThis(firstParam, [1,2,3]);
>
> doesn't really need the [] in this case since the last parameters would
> have to be an array of const.
>

>From the view of the *caller* you are mostly right. Though the square
brackets can't be left away, cause we're talking about an array parameter
here. If it would be allowed for array of const then it would also need to
be allowed for other open array parameters for consistency. But then it
wouldn't be consistent with open array arguments in the middle. Each
exception makes the language more complex.
Fun fact: There is in fact one such case for open arrays: a single element
may be passed without the square brackets.

Also a further difference is that "array of const" does not need to be the
last parameter and you can have multiple such parameters in the same call.
And it can be used with any calling convention.

Please note that it is possible in FPC to declare an external, variadic
function with an "array of const" parameter instead of varargs. The call
then looks like a normal "array of const" call in Object Pascal, but
internally the arguments are passed using the variadic ABI.

For the *callee* things are vastly different however. With "array of const"
you can determine both the amount of arguments as well as the type of each.
In variadic functions that either needs to be fix inside the function (e.g.
the optional mode parameter of the Posix open() function) or it needs some
kind of schematic (the format string in printf/scanf) to determine the
argument types.

Regards,
Sven

>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-devel/attachments/20191210/13fbbdd8/attachment.html>


More information about the fpc-devel mailing list