This is the mail archive of the 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: [PATCH] PR 7776: Warn about if ("abc" < "xyz") ...

On Sun, Jun 05, 2005 at 12:31:34PM -0600, Roger Sayle wrote:
> On Sun, 5 Jun 2005, Daniel Jacobowitz wrote:
> > So, all comparisons in which either side is a string literal.  I don't
> > think that's a good choice.  What about this:
> >
> >   if ("foo" == NULL)
> >
> > Maybe there are no other interesting special cases besides == 0 and
> > != 0.
> Some could argue that this construct is just as broken.

Have you ever worked on a large project making use of the C preprocessor?

#define FOO a_var
#define BAR "a_string"
#define BAZ(x) do { if ((x) != NULL) append(x); } while (0)


We should warn for constructs which have unspecified, unportable, or
surprising behavior.  Comparison of a string literal against NULL has
clear, portable, and predictable behavior.  I don't see the point.

You're right that
  char *ptr = NULL;
  if (ptr == "foo")
also has clearly specified behavior; but I don't see an analagous way
to present that to the compiler.  I'm sure we could think of one if we
tried hard enough but that doesn't mean we need to bend over backwards
for it.

Daniel Jacobowitz
CodeSourcery, LLC

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