qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [PATCH 02/40] elf: Add notes implementation


From: Michael Matz
Subject: Re: [Qemu-devel] [PATCH 02/40] elf: Add notes implementation
Date: Tue, 2 Nov 2010 11:17:55 +0100 (CET)

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.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]