Of course, what you do in that condition is a comparison between pointers (use strcmp
to compare C strings).
So, I think it is a compiler translation/optimization that "maps" identical literals at the same location in the memory.
EDIT 1:
The following sample confirms what I wrote:
#include <stdio.h>
char* a = "ffffd";
char* b = "ffffd";
char* c = "ffffd";
int main() {
printf ("a => %p\nb => %p\nc => %p\n", a, b, c);
}
The previous program, compiled with gcc
using -O0
and executed will print:
a => 0x40060c
b => 0x40060c
c => 0x40060c
I don't know how other compilers will treat the same situation.