Markus Gerwinski wrote:
Alternatively, I could need a mechanism to absorb the runtime error fired by "as" before it interrupts the program.
In Delphi, from what the help file says, the program should not compile if the typecasting is wrong. GPC could do the same.
??? How should the compiler know? I mean, the object type of a pointer at runtime is a matter of runtime.
I think what's meant is if the types involved are not ancestors of each other, i.e. in `foo [ia]s bar' if foo is of declared type ^baz, and neither bar is derived from baz or vice versa, then the compiler can know that the check is wrong.
There's another trivial case when bar is an ancestor of baz. In this case, the check is always true. I don't know what Delphi does in this case, but I think GPC should at least give a warning, like it does when comparing an unsigned value >= 0.
The interesting case, of course, is when baz is an ancestor of bar, and this requires a runtime check.
Frank