[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#517653: gcc-4.3: "warning: comparison with string literal results in unspecified behavior" when comparing two different literals



Bastian Blank <waldi@debian.org> writes:

> §6.4.5 6) say:
> | It is unspecified whether these arrays are distinct provided their
> | elements have the appropriate values.

If the arrays resulting from "hello" and "there" were not
distinct from each other, then their elements would not have the
appropriate values.  Therefore, the two arrays must be distinct.

"hello" == "hello" is unspecified.
"there" == "titanothere" + 6 is unspecified.
"hello" < "there" is undefined.
"hello" == "there" however must be false.

> Also string literals are no pointers and don't need to have an address.

I don't think I claimed string _literals_ were pointers or had
addresses.  In the expression "hello" == "there" though, pointers
are compared.  I guess the warning was imprecisely worded to keep
it shorter.

When a string literal is used as a primary expression (ISO/IEC
9899:1999 6.5.1p4) that is an operand of the == operator, the
characters of the string literal are used to initialize an array
of static storage duration (6.5.4p5), which is then converted to
a pointer to the first element of the array (6.3.2.1p3).  This
pointer is an address constant (6.6p9).

Attachment: pgpoki39cUsat.pgp
Description: PGP signature


Reply to: