On 11/01/2010 10:17 PM, Alexander Graf wrote:
Let's ask someone who definitely knows:).
LOL, hi Michael! :)
Michael, is code like
char *x = a, *y = b;
if (x < y) {
...
}
valid? Or do I first have to cast x and y to unsigned longs or uintptr_t?
It is, as long as x and y point into the same object (in your original
code, data[0]...data[data_len] is the object). This instead
char *x = a;
long *y = b;
if (x < y)
{
}
should give a warning
g2.c:1: warning: comparison of distinct pointer types lacks a cast
but is also valid as long as x and y point into the same object. To
quiet the warning you should _not_ cast x to long* however (unless you
know it's properly aligned); casting y to char* instead is fine.
Paolo