[fpc-pascal] Illogical automatic dereferencing
Jürgen Hestermann
juergen.hestermann at gmx.de
Tue Oct 13 14:50:42 CEST 2009
> About pointer arithmetic:
> IMO memory is an array. So for me it is quite natural that P^ and P[0]
> are the same.
You are missing the point. If you already *know* that you are dealing
with a pointer (to an array), then of course you may use this workaround
(it's nothing else, because if I want to specify the whole array why
should I use the first element only?). It was stated here many times
that the user should not care about how these dynamic arrays are handled
but in reality he has to.
And even if he is aware of it the syntax is not logical. If the first
element of the array is not zero, you cannot use your workaround. You
have to check the numbering first and if you change this later you have
to change your P[0] syntax too. Or you use P[low(P)] (again I am not
sure whether I can use "low(P)" in this construct or whether I have to
use "low(P^)". But then it already has become realy awkward. You should
be able to use an unambiuous syntax to specify the whole array which
does not seem to exist anymore.
Either the (hidden) pointer to array logic is fully transparent (which
means, the user can use the same syntax as for standard arrays) or the
user should know about it but then it should not be hidden. Now we have
a mix of both.
> The only disturbing is the automatic dereferencing of pointer to
> record/object in Delphi mode, where you can use PtrRect^.Left and
> PtrRect.Left.
> But that only works in delphi mode, which I avoid.
Why is this more disturbig than for arrays? It's the same story.
> Great power comes with great responsibility.
Yes. Then use C or assembler. You are "responsible" for everything and
you cannot expect any help from the compiler.
More information about the fpc-pascal
mailing list