[fpc-pascal] Do you get type errors?
Jürgen Hestermann
juergen.hestermann at gmx.de
Sun Jun 20 18:13:04 CEST 2010
> Now, it is easy for the compiler to guess such cases.
I don't want the compiler to "guess" at all.
> Some languages perform automagic deferencing of pointers to structured types (record/object, array), meaning eg
> p.x
> is interpreted as
> p^.x
> and
> p[i]
> is interpreted as
> p^[i]
Yes, it has even become part of Free Pascal (AnsiStrings, Open Arrays). Still I don't like it. And it was only an example for the benefit of type checking when using pointers heavily. And wasn't there also the possiblity of pointer arithmetic...?
> There is no ambiguity since the pointer nature of p is known by the compiler before such lookups can be parsed.
It's not only a question of ambiguity. I may not have fully understood you question but how would you *avoid* type checking? If you assign an integer to a set variable the compiler should complain, shouldn't it? If no type checking is done then simply only bytes are moved? That's assembler...
> Nice use of the compiler ;-) But only needed since implicite dereferencing is not a feature of the language.
No. If you need access to the pointers themselves you cannot have implicit derefferencing. That's the general problem with AnsiStrings and Open Arrays already. It becomes a real problem when you create your own data types which make use of pointers heavily. Then you *need* access to the pointers themself *and* to the data they point to. This would be impossible with automatic derefferencing.
More information about the fpc-pascal
mailing list