[fpc-pascal] Optional param modifier

Benito van der Zander benito at benibela.de
Sat Apr 13 18:40:59 CEST 2019


the parameter is already optional without any modifier, since you can 
always pass nil for it.

Perhaps there could be the opposite modifier, so the function cannot be 
called with nil. Like

procedure DoThis(nonnil var obj: TObject);

and then you need to check if it is nil, before calling DoThis .

Or you put it in the type. type TSomeObject = nonnil class(TObject)... 
and then it would never be allowed to be nil.
Or for pointers type PDude = nonnil ^TDude;
If you would want to use such a nonnil class as field in another class, 
you would need to initialize it in the constructor.


Am 13.04.19 um 09:47 schrieb Sven Barth via fpc-pascal:
> Marco van de Voort <fpc at pascalprogramming.org 
> <mailto:fpc at pascalprogramming.org>> schrieb am Fr., 12. Apr. 2019, 20:56:
>     Op 2019-04-12 om 17:23 schreef Ryan Joseph:
>     >
>     > What do you think of that? Sounds like an easy way to get some
>     support for nil pointers deref’s and provides self documenting code.
>     I think the same as when I read the suggestion for an inout
>     variant of
>     VAR. Move this out of the language syntax, and make it directives or
>     attribute like syntax (like we will need to get anyway for const ref).
> Im definitely for new syntaxes (or the attribute one) than a 
> directive. A directive can be anywhere and I'd need to go looking for 
> it if I want to know whether it is set or not. Some syntax extension 
> would be right at the declaration.
> So, yeah, we'll probably compromise towards the attribute syntax...
> Regards,
> Sven
> _______________________________________________
> fpc-pascal maillist  -  fpc-pascal at lists.freepascal.org
> http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20190413/f87cc44f/attachment.html>

More information about the fpc-pascal mailing list