From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 16916 invoked by alias); 13 Jul 2005 13:53:41 -0000 Mailing-List: contact gcc-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-owner@gcc.gnu.org Received: (qmail 16903 invoked by uid 22791); 13 Jul 2005 13:53:37 -0000 Received: from rproxy.gmail.com (HELO rproxy.gmail.com) (64.233.170.193) by sourceware.org (qpsmtpd/0.30-dev) with ESMTP; Wed, 13 Jul 2005 13:53:37 +0000 Received: by rproxy.gmail.com with SMTP id g11so203007rne for ; Wed, 13 Jul 2005 06:53:36 -0700 (PDT) Received: by 10.38.151.73 with SMTP id y73mr790610rnd; Wed, 13 Jul 2005 06:53:36 -0700 (PDT) Received: by 10.38.76.22 with HTTP; Wed, 13 Jul 2005 06:53:36 -0700 (PDT) Message-ID: <118833cc0507130653e8fc6ae@mail.gmail.com> Date: Wed, 13 Jul 2005 13:53:00 -0000 From: Morten Welinder Reply-To: Morten Welinder To: gcc@gcc.gnu.org Subject: Re: Pointers in comparison expressions Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline X-SW-Source: 2005-07/txt/msg00550.txt.bz2 > Relational tests between pointers is only allowed by > the ISO C standard if the two pointers point into the > same array, or if a pointer points to exactly one byte > beyond the array. There actually is a way to compare arbitrary data pointers within the C standards: you send the pointers through a printf- type function using "%p" and strcmp the results. That'll give you some kind of ordering, though not necessarily the obvious one. (No, I am not serously suggesting that anyone in their right mind you actually do so. Why does this keyboard have a smiley key?) Note, btw., that such use of %p also rules out using a garbage collector for C and C++. It simply cannot work if some of your pointers have been sent off by email to the other end of the world. At the very least you would have to consider any pointer that made it through %p to be live forever. Morten