Florian Klaempfl wrote on Tue, 13 Oct 2009:

Jonas Maebe schrieb:
I think that "all pointers can be indexed as arrays" can easily cause
accidentantal errors though. I can't find it anymore, but I remember
Pierre once fixed a bug in the compiler sources itself where someone
accidentally used move(pstring_var[1],...) instead of
move(pstring_var^[1],..). That at least was not a case of not
understanding how pointers work, but a simple case of a typo which
couldn't be caught anymore by the compiler due to this extension.

What is the alternative?

Only allowing it for pchar/pwidechar, I guess. And/or printing a warning in case you are "indexing a pointer" to a type that is an indexed type itself, although I'm not sure how we could make it possible to disable this warning on a case-by-case basis using some kind of explicit syntax saying "yes, I want (pointer+(n-1)*sizeof(pointer))^, not pointer^[n]".

Declare things like

tchar = array[0..maxint] of char;
pchar = ^tchar;

?

Small typo, move(p,... instead of move(p^,... and things break as well

The point is that it creates an extra class of small typos that can't be caught by the compiler if you allow it for all types. At least TP (and previous versions of Delphi) only allowed this for pchar/pwidechar afaik, where this particular error cannot occur (p^[i] is not valid if p is a pchar).


Jonas

----------------------------------------------------------------
This message was sent using IMP, the Internet Messaging Program.

_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Reply via email to