Comparing pointers (including extensions)
Comparing pointers (including extensions)
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.)
-
- Site Admin
- Posts: 525
- Joined: Fri Dec 31, 2010 12:30 pm
- Contact:
Re: Comparing pointers (including extensions)
The current version of Astrobe allows this. Do you have any reason to believe it should not?
Re: Comparing pointers (including extensions)
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?
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?
-
- Site Admin
- Posts: 525
- Joined: Fri Dec 31, 2010 12:30 pm
- Contact:
Re: Comparing pointers (including extensions)
Yes. Wherever comparison and assignment are both allowed it would not make sense to me if the corresponding compatibility conditions were not consistent.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?
Re: Comparing pointers (including extensions)
I took the same view in my compiler. It's just the lack of precision in the official definition that bugs me...