public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
From: Joe Buck <Joe.Buck@synopsys.COM>
To: Falk Hueffner <falk@debian.org>
Cc: Dave Korn <dave.korn@artimi.com>,
	"'Daniel Berlin'" <dberlin@dberlin.org>,
	mrc.lrn@inwind.it, gcc@gcc.gnu.org
Subject: Re: Pointers in comparison expressions
Date: Tue, 12 Jul 2005 23:17:00 -0000	[thread overview]
Message-ID: <20050712231649.GB7290@synopsys.com> (raw)
In-Reply-To: <87fyujd50s.fsf@debian.org>

On Wed, Jul 13, 2005 at 12:38:11AM +0200, Falk Hueffner wrote:
> Erik Trulsson <ertr1013@student.uu.se> 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	other threads:[~2005-07-12 23:17 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-07-12 16:24 Mirco Lorenzoni
2005-07-12 16:32 ` Daniel Berlin
2005-07-12 16:53   ` Dave Korn
2005-07-12 21:00     ` Andreas Schwab
2005-07-12 21:42     ` Erik Trulsson
2005-07-12 22:09       ` Joe Buck
2005-07-12 22:28         ` Erik Trulsson
2005-07-12 22:38           ` Falk Hueffner
2005-07-12 23:17             ` Joe Buck [this message]
2005-07-12 23:28               ` Falk Hueffner
2005-07-13  2:02                 ` Joe Buck
2005-07-13 21:42                 ` Olivier Galibert
2005-07-12 23:27             ` Michael Meissner
2005-07-12 22:46           ` Joe Buck
2005-07-16 11:49       ` Vincent Lefevre
2005-07-17 16:55         ` Paul Koning
2005-07-18  1:49           ` Vincent Lefevre
2005-07-18  3:13             ` D. Hugh Redelmeier
2005-07-18 13:13               ` Paul Koning
2005-07-18 13:09             ` Paul Koning
2005-07-12 17:03 ` chris jefferson
2005-07-12 23:18 ` Michael Meissner
2005-07-22 23:20 ` Geoffrey Keating
2005-07-13 13:53 Morten Welinder
2005-07-24  1:13 Paul Schlie
2005-07-26  4:43 ` Geoff Keating

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20050712231649.GB7290@synopsys.com \
    --to=joe.buck@synopsys.com \
    --cc=dave.korn@artimi.com \
    --cc=dberlin@dberlin.org \
    --cc=falk@debian.org \
    --cc=gcc@gcc.gnu.org \
    --cc=mrc.lrn@inwind.it \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).