[Vm-dev] Question about pointer comparison

Eliot Miranda eliot.miranda at gmail.com
Wed Mar 25 15:47:21 UTC 2015


Hi Nicolas,

On Mar 25, 2015, at 6:14 AM, Nicolas Cellier <nicolas.cellier.aka.nice at gmail.com> wrote:

> 
> 
> 2015-03-25 12:52 GMT+01:00 David T. Lewis <lewis at mail.msen.com>:
>> 
>> On Tue, Mar 24, 2015 at 10:32:32PM -0700, Eliot Miranda wrote:
>> >
>> > On Tue, Mar 24, 2015 at 8:33 PM, Nicolas Cellier <
>> > nicolas.cellier.aka.nice at gmail.com> wrote:
>> >
>> > >
>> > > Hi,
>> > >
>> > > in checkStackIntegrity, there is a comparison of char *
>> > >
>> > > theSP <= frameRcvrOffset
>> > >
>> > > Is it OK, or should we better use oop:isLessThanOrEqualTo: ?
>> > >
>> >
>> > Providing that both are typed as non-void pointers to the same type this
>> > will work.  oop:isLessThanOrEqualTo: is there for comparing sqInt values
>> > (i.e. oops) as this is a signed type and oop:isLessThanOrEqualTo: forces an
>> > unsigned comparison.
>> 
>> Agreed, both variables are (char *), so the pointer comparison is OK as written.
>> 
>> Dave
> 
> OK, thanks both, I see it better now.
> It's specified in ISO/IEC 9899:TC3, 6.5.8 rule 5 (relational operators)
> (draft available at http://www.open-std.org/JTC1/SC22/WG14/www/docs/n1256.pdf)
> 
> Strictly speaking, behavior is undefined when comparing two pointers that do not point to the same aggregate or to the same array, but i guess we can live with that.

yes, and here's why (IMO).  

a) that comparison between two distinct aggregates is undefined is to allow exotic (object oriented) systems to implement C; we're unlikely ever to encounter such things

b) converting to integers is not going to magically fix undefinedness.  I can't imagine an implementation that would be able to fix the undefinedness when converting to integers but wouldn't when comparing two pointers.

So IMO this being undefined is plain silly.  It's always going to be defined.  I'm sure I'm wrong, but I'd like to hear a well-reasoned rationale as to why.


> 
> Cheers
> 
> Nicolas
> 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.squeakfoundation.org/pipermail/vm-dev/attachments/20150325/d282e868/attachment.htm


More information about the Vm-dev mailing list