This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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....


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]