From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from [140.186.70.92] (port=36898 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PDH3a-0004hT-CZ for qemu-devel@nongnu.org; Tue, 02 Nov 2010 09:37:53 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PDDwG-0006Jo-Ug for qemu-devel@nongnu.org; Tue, 02 Nov 2010 06:18:02 -0400 Received: from cantor.suse.de ([195.135.220.2]:33966 helo=mx1.suse.de) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PDDwG-0006JA-Pc for qemu-devel@nongnu.org; Tue, 02 Nov 2010 06:18:00 -0400 Date: Tue, 2 Nov 2010 11:17:55 +0100 (CET) From: Michael Matz Subject: Re: [Qemu-devel] [PATCH 02/40] elf: Add notes implementation In-Reply-To: Message-ID: References: <1288623713-28062-1-git-send-email-agraf@suse.de> <1288623713-28062-3-git-send-email-agraf@suse.de> <4CCF0A13.1060202@mail.berlios.de> <4CCF20BE.8010205@mail.berlios.de> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Alexander Graf Cc: Blue Swirl , qemu-devel Developers , Gerd Hoffmann Hi, On Mon, 1 Nov 2010, Alexander Graf wrote: > > No. Pointers of same type which are not void pointers can be compared. > > > > There is even a data type ptrdiff_t, so you can also compare their > > difference with zero. > > Let's ask someone who definitely knows :). > > Michael, is code like > > char *x = a, *y = b; > if (x < y) { > ... > } Pointers can be compared iff they point into the same object (including right after the object), so it depends on what a and b were above. This would be invalid for instance: int o1, o2; int *p1 = &o1, *p2 = &o2; if (p1 < p2) ... > valid? Or do I first have to cast x and y to unsigned longs or > uintptr_t? For doing a valid pointer comparison you don't have to cast anything. Casting doesn't make an invalid comparison valid. Ciao, Michael.