Why do (only) some compilers use the same address for identical string literals?

后端 未结 4 2227
北恋
北恋 2020-12-13 01:07

https://godbolt.org/z/cyBiWY

I can see two \'some\' literals in assembler code generated by MSVC, but only one with clang and gcc. This leads to totally

4条回答
  •  一个人的身影
    2020-12-13 02:09

    Whether or not a compiler chooses to use the same string location for A and B is up to the implementation. Formally you can say that the behaviour of your code is unspecified.

    Both choices implement the C++ standard correctly.

提交回复
热议问题