[fpc-pascal] Illogical automatic dereferencing
Jürgen Hestermann
juergen.hestermann at gmx.de
Sat Oct 10 13:13:03 CEST 2009
> 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.
Well, it is now much too late to change this but it annoys me all the time.
More information about the fpc-pascal
mailing list