This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
RE: Pointers in comparison expressions
- From: "Dave Korn" <dave dot korn at artimi dot com>
- To: "'Daniel Berlin'" <dberlin at dberlin dot org>,<mrc dot lrn at inwind dot it>
- Cc: <gcc at gcc dot gnu dot org>
- Date: Tue, 12 Jul 2005 17:54:00 +0100
- Subject: RE: Pointers in comparison expressions
----Original Message----
>From: Daniel Berlin
>Sent: 12 July 2005 17:33
>> I think that even if the use of relational operators other than '==' and
>> '!=' is legal with pointers, the compiler should issue a warning (when
>> the option -Wall is used), as it does for assignment, used as truth
>> values, not surrounded with parentheses.
>
> Why?
> It's legal, it's useful, and used.
>
> --Dan
Just to enlarge upon Dan's comment:
Since pointer subtraction is well defined, and it returns an int, then ...
int *a, *b;
if (a < b)
dosomething ();
... is just the same as ...
int *a, *b;
if ((b - a) >= 0)
dosomething ();
... so do you think the compiler should warn about _all_ pointer arithmetic?
cheers,
DaveK
--
Can't think of a witty .sigline today....