warning: comparison with string literal results in unspecified behavior [-Waddress]
Alexander Monakov
amonakov@ispras.ru
Wed Oct 10 09:39:00 GMT 2018
On Wed, 10 Oct 2018, Josef Wolf wrote:
> Is there any reason, that a pointer to a string literal can change?
If you have two string literals in your program, their addresses may be
different even if the two literals have identical contents.
Unification of string literals is an optimization, you cannot rely on a
particular optimization to always happen.
You can see for yourself if you prepare a test with two translation units,
each with a function like
const char *f1()
{
return "Hello world";
}
you should see f1() != f2() if the two units are compiled with -O0.
Alexander
More information about the Gcc-help
mailing list