[fpc-devel] Thoughts on being able to declare "pointer-to-type" parameters directly in method signatures?

Jonas Maebe jonas at freepascal.org
Fri Jun 7 19:46:49 CEST 2019


On 07/06/2019 18:37, Ben Grasset wrote:
> B) Is there a specific reason is has *not* been implemented previously? 
> (Seems unlikely)

Pascal does not support declaring any new types inside parameter lists, 
apart from
a) local procvar types (in ISO/MacPas modes)
b) open arrays

In both cases, theses can in fact only be declared in parameter lists 
(at least in their original dialects). In case of a), the reason is that 
this prevents you from accidentally assigning a local procvar to a 
variable in an outer scope and then call it when it is no longer valid. 
In case of b), the reason is that they don't make sense outside the 
context of a parameter list.

It would be inconsistent to only allow such declaration for pointers, 
and not for other types (a programming language should strive to be as 
orthogonal as possible, with as few exceptions as possible). But then 
you get issues with a.o. open arrays vs dynamic arrays, and record 
compatibility (structurally equivalent records are not 
assignment-compatible in Pascal).

Additionally, when extending a language, the question should always be 
"does this greatly improve programmer efficiency, code safety, 
portability, performance, ...", rather than "is there a reason why this 
has not been added". The reason is that extending a language also always 
comes with inherent downsides: slower/more complex parser, more complex 
documentation, incompatibilities with other compilers, potential future 
conflicts with other compilers if they extend it in a conflicting way, ...


Jonas



More information about the fpc-devel mailing list