I can see two 'some'
literals in assembler code generated by MSVC, but only one with clang and gcc. This leads to totally different results of code execution.
static const char *A = "some";
static const char *B = "some";
void f() {
if (A == B) {
throw "Hello, string merging!";
}
}
Can anyone explain the difference and similarities between those compilation outputs? Why does clang/gcc optimize something even when no optimizations are requested? Is this some kind of undefined behaviour?
I also notice that if I change the declarations to those shown below, clang/gcc/msvc do not leave any "some"
in the assembler code at all. Why is the behaviour different?
static const char A[] = "some";
static const char B[] = "some";