On Wed, Jul 13, 2005 at 12:38:11AM +0200, Falk Hueffner wrote:
> Erik Trulsson <[EMAIL PROTECTED]> writes:
> > I believe most C compilers support it in practice, but few, if any, have
> > actually documented it as a supported extension to C.
> 
> I don't think we should, either. People who want to do this can just
> cast both pointers to size_t.

If you want to be pedantic, that's not portable; in particular, it will
break for some of the memory models used with 16-bit Windows (if you never
had to program those, thank your favorite deity).  The reason is that, in
those modes, different objects can be in different segments, but pointers
are only 16 bit.  Casting them to size_t won't make them compare correctly
or reliably.  But for the kind of uses I was describing, that's not a
problem: you first cast the pointers into "huge pointers", which are 32
bit, and those huge pointers can be compared reliably.  (Complicating the
picture were "far pointers", which might be equal but not compare equal if
there are overlapping segments).

The conclusion is that a direct pointer comparison is just as good as
casting to size_t first.

Reply via email to