In C language, is compiler/linker obligated to put the same string literal used multiple times into single memory location?
const char* a = "abcdef";
const char* b = "abcdef";
//Compare pointers
if (a == b) {
printf("True\r\n");
} else {
printf("False\r\n");
}
In this case, is statement above always true (in MSVC 2017 it is) or is it undefined behavior in general?
Can it happen that we have string literal abcdef
in 2
different memory locations? Of course, I do not count strings like 12abcdefgh
˛where abcdef
is part of string, but standalone.