I have some strange behaviour from my compiler. If a particular string already has been defined, then if I define another variable with the same string value, it actually gets pointed to the original instance. e.g.
const char * a = "dog";
const char * b = "dog";
printf("a = %p\n",a);
printf("b = %p\n",b);
Example output is
a = 00404060
b = 00404060
It is not wrong I guess but I wonder if is compiler specific or if there are any rules about this. The question arose because someone working for me wrote a fucntion that was supposed to compare and count string matches. In fact they compared and counted pointer values yet were still getting the correct answer.
I'm using gcc (or g++) 4.6.3