Re: warning: comparison with string literal results in unspecified behavior [-Waddress]

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

 



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



[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux