From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 20450 invoked by alias); 12 Jul 2005 23:18:05 -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 20427 invoked by uid 22791); 12 Jul 2005 23:17:59 -0000 Received: from metal-man.the-meissners.org (HELO tiktok.the-meissners.org) (66.205.90.83) by sourceware.org (qpsmtpd/0.30-dev) with ESMTP; Tue, 12 Jul 2005 23:17:59 +0000 Received: from tiktok.the-meissners.org (localhost [127.0.0.1]) by tiktok.the-meissners.org (8.12.11/8.12.11) with ESMTP id j6CNC9SC007040; Tue, 12 Jul 2005 19:12:09 -0400 Received: (from meissner@localhost) by tiktok.the-meissners.org (8.12.11/8.12.11/Submit) id j6CNC9qW007039; Tue, 12 Jul 2005 19:12:09 -0400 Date: Tue, 12 Jul 2005 23:18:00 -0000 From: Michael Meissner To: gcc@gcc.gnu.org Cc: mrc.lrn@inwind.it Subject: Re: Pointers in comparison expressions Message-ID: <20050712231209.GC6903@tiktok.the-meissners.org> Mail-Followup-To: Michael Meissner , gcc@gcc.gnu.org, mrc.lrn@inwind.it References: <200507121825.45472.mrc.lrn@inwind.it> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <200507121825.45472.mrc.lrn@inwind.it> User-Agent: Mutt/1.4.1i X-SW-Source: 2005-07/txt/msg00535.txt.bz2 On Tue, Jul 12, 2005 at 06:25:45PM +0200, Mirco Lorenzoni wrote: > Can a pointer appear in a C/C++ relational expression which doesn't test the > equality (or the inequality) of that pointer with respect to another pointer? > For example, are the comparisons in the following program legal code? > > /* test.c */ > #include > > int main(int argc, char* argv[]) > { > void *a, *b; > int aa, bb; > > a = &aa; > b = &bb; > > printf("a: %p, b: %p\n", a, b); > if (a < b) > printf("a < b\n"); > else > printf("a >= b\n"); > > if (b < a) > printf("b < a\n"); > else > printf("b >= a\n"); > return 0; > } No, this is not legal. 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. > > P.S. > I'm not a list subscriber. Send me a copy of your reply, please. Ummm, I don't understand how you expect to get replies if you don't monitor the list. -- Michael Meissner email: gnu@the-meissners.org http://www.the-meissners.org