Comparing pointers (including extensions)

Topics related to the use of Oberon language features
Locked
kevinhely
Posts: 29
Joined: Wed May 18, 2011 3:35 am

Comparing pointers (including extensions)

Post by kevinhely » Wed Jan 09, 2013 5:26 pm

Is a comparison p = q allowed, where p is of type POINTER TO Car (say) and q is of type POINTER TO SportsCar, where SportsCar is an extension of Car? (It's possible for p to point at a record of type SportsCar.)

cfbsoftware
Site Admin
Posts: 493
Joined: Fri Dec 31, 2010 12:30 pm
Contact:

Re: Comparing pointers (including extensions)

Post by cfbsoftware » Sat Jan 12, 2013 11:45 pm

The current version of Astrobe allows this. Do you have any reason to believe it should not?

kevinhely
Posts: 29
Joined: Wed May 18, 2011 3:35 am

Re: Comparing pointers (including extensions)

Post by kevinhely » Sun Jan 13, 2013 2:47 am

Well, as in our previous discussions, it's hard to be sure what the official answer is.

The rule for relational expressions is that "both operands must be of the same type". That's not stated in the section on relational expressions but Wirth told me that it "obvious[ly]" holds over from the section on arithmetic operators(!).

Then again, the rule for assignment permits mixing pointer types as long as one is an extension of the other. I guess that's why it's permitted to mix them in relational expressions in Astrobe, right?

Perhaps the specification requires something like p(SportsCar) = q, and that we can only write p = q if p and q share the same type name?

cfbsoftware
Site Admin
Posts: 493
Joined: Fri Dec 31, 2010 12:30 pm
Contact:

Re: Comparing pointers (including extensions)

Post by cfbsoftware » Sun Jan 13, 2013 12:35 pm

kevinhely wrote:Then again, the rule for assignment permits mixing pointer types as long as one is an extension of the other. I guess that's why it's permitted to mix them in relational expressions in Astrobe, right?
Yes. Wherever comparison and assignment are both allowed it would not make sense to me if the corresponding compatibility conditions were not consistent.

kevinhely
Posts: 29
Joined: Wed May 18, 2011 3:35 am

Re: Comparing pointers (including extensions)

Post by kevinhely » Sun Jan 13, 2013 7:59 pm

I took the same view in my compiler. It's just the lack of precision in the official definition that bugs me...

Locked