[fpc-pascal] Illogical automatic dereferencing

Henry Vermaak henry.vermaak at gmail.com
Sat Oct 10 13:43:34 CEST 2009


2009/10/10 Jürgen Hestermann <juergen.hestermann at gmx.de>:
>> Its a common mistake to use @<dynamic array var> instead of @<dynamic
>> array var>[ 0 ].
>
> IMO this happens because of an illogical design flaw (which seems to be
> introduced by Borland). If I have a variable that is a *pointer* to an array
> then why is it possible to use the square brackets to use it as if  it was
> an array? The derefencing symbol ^ should be needed here (X^[1] instead of
> X[1]). It's the same for PCHAR. It is a pointer and there should not be any
> automatic derefencing. That obscures the type origin and is not in the
> spirit of Pascal. And it leads to the mistakes mentioned above. It is C-like
> style ("the compiler will guess what you meant") which should never have
> crept into Pascal. If you build a complex data structure with nested
> pointers and arrays you get into hell with this automatic dereferencing.

This behaviour comes from C syntax.  The array is a pointer, which you
dereference by using the square brackets.  This is well defined
syntax, nothing automatic or illogical about it.  The only reason
pascal programmers make mistakes with this is because they are less
accustomed to using pointers.

Henry



More information about the fpc-pascal mailing list