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 <stdio.h>
> 
> 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: [EMAIL PROTECTED]
http://www.the-meissners.org

Reply via email to