Post by August KarlstromIf the type descriptor of Pb is passed along with the pointer pa (as a
hidden parameter) the call to NEW can allocate a variable of type Tb
instead. Maybe that's how it's done in Ulm Oberon.
You arouse my curiosity :-)
I played with Ulm Oberon long time ago and the above code did not crash or gave unexpected results (typical of loopholes). I haven't investigated further at that time, but I supposed pb.b overwrites an adiacent block in the heap.
But looking at the first field of the type descriptor (in Ulm Oberon it's the type's size):
SYSTEM.GET(SYSTEM.ADR(pb^)-4, adr);
SYSTEM.GET(adr, tpsize);
Write.Int(tpsize, 1);
It outputs 8 (instead of 4), then you are right and it was allocated as Tb and not Ta! A nice trick to avoid the loophole (although not very intuitive).
Now the real question: is it a safe trick? Well, we are allocating a variable of type Ta as Tb, but Tb *is* Ta. The world is safe.
But there is another question: why this trick has been excluded in Oberon? There are two reasons that come to my mind:
1) Code obscurity: we are allocating a variable of a different type (although an extension of it) with a different size. This defeats predictability of code.
2) Another hidden parameter: in Oberon only two types of parameters have a hidden parameter, open arrays and variable parameters of records. This requires that also variable parameters of pointers must carry a hidden parameter.
Wirth is usually against hidden things, but I'm more inclined to believe that 1) is the main reason.