Page 1 of 1

Comparing pointers (including extensions)

Posted: Wed Jan 09, 2013 5:26 pm
by kevinhely
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.)

Re: Comparing pointers (including extensions)

Posted: Sat Jan 12, 2013 11:45 pm
by cfbsoftware
The current version of Astrobe allows this. Do you have any reason to believe it should not?

Re: Comparing pointers (including extensions)

Posted: Sun Jan 13, 2013 2:47 am
by kevinhely
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?

Re: Comparing pointers (including extensions)

Posted: Sun Jan 13, 2013 12:35 pm
by cfbsoftware
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.

Re: Comparing pointers (including extensions)

Posted: Sun Jan 13, 2013 7:59 pm
by kevinhely
I took the same view in my compiler. It's just the lack of precision in the official definition that bugs me...