? "\0abc" : "\0xyz"
D. J. Bernstein
djb@cr.yp.to
Wed Dec 22 15:42:00 GMT 1999
The following code produces incorrect results under gcc 2.8.1, incorrect
results under egcs 2.91.66, correct results under gcc 2.7.2.3, and
_presumably_ (see below) incorrect results under the latest gcc:
doit(int flag)
{
printf(1 + (flag ? "\0wrong\n" : "\0right\n"));
}
main()
{
doit(0);
}
I'm not familiar with the gcc internals, but after a minute of poking
around I found the fragment
case STRING_CST:
return (TREE_STRING_LENGTH (arg0) == TREE_STRING_LENGTH (arg1)
&& ! strncmp (TREE_STRING_POINTER (arg0),
TREE_STRING_POINTER (arg1),
TREE_STRING_LENGTH (arg0)));
in gcc.gnu.org/cgi-bin/cvsweb.cgi/~checkout~/egcs/gcc/fold-const.c.
Remember that, according to the C standard, a character string literal
is an array of bytes, not necessarily a string.
---Dan
More information about the Gcc-bugs
mailing list