[fpc-devel] Thoughts on being able to declare "pointer-to-type" parameters directly in method signatures?
Ben Grasset
operator97 at gmail.com
Fri Jun 7 21:06:16 CEST 2019
On Fri, Jun 7, 2019 at 2:35 PM Jonas Maebe <jonas at freepascal.org> wrote:
> None of these can be defined as a type in parameter lists. Keep in mind
> that "^Type" defines a new type. Semantically, it's at the same level as
> "0..5" and "record a, b: longint end;".
>
Right, that's the point. There's nothing else that *would* make any
syntactic sense in a parameter list besides "^Type" that isn't already
allowed in them.
On Fri, Jun 7, 2019 at 2:35 PM Jonas Maebe <jonas at freepascal.org> wrote:
> Your "^Type" inline type definition would behave exactly the same as a
> regular pointer type definition.
>
Of course. It would be strange if it didn't, I think. That's the whole
point.
Here's another more simplistic example, in {$mode ObjFPC} this time:
program Example;
{$mode ObjFPC}
generic procedure GenProc<T>(Param: ^T); // <-- does not compile
var
P: ^T; // <-- compiles just fine
begin
end;
procedure NonGenProc(Param: ^LongInt); // <-- does not compile
var
P: ^LongInt; // <-- compiles just fine
begin
end;
begin
end.
To me it's always seemed illogical (in various different Pascal compilers
over time, not just FPC) that the "parameter" declarations there don't
work, whereas things like the "var" ones (which are just as "inline", I'd
say) work just fine.
It comes across as the kind of thing that would happen if someone simply
forgot to account for the "^" symbol in their code for parsing method
signatures, not like any kind of intentional design choice.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-devel/attachments/20190607/6e80b544/attachment.html>
More information about the fpc-devel
mailing list