The idea, was to show that when you compile with the /GF flag set, string pooling is enabled, and the constchar*'s which point to string literals would point to the same, read-only memory location.
However, the addresses are still different.
What's the deal? Obviously, I'm compiling with /GF set. What am I missing here?
I'm using VC++2008 IDE if it makes a difference.
Maybe you have some other optimization flag conflicting with this? Also, string1 and string2 will always have different addresses from each other and from string3 and string4. The only candidates for seeing string pooling here are string3 and string4, but it's not guaranteed afaik.
Also, string1 and string2 will always have different addresses from each other and from string3 and string4.
Yes I know :). They're just there to demonstrate the difference between character arrays and string literals.
As far as I know, there are no conflicting flags set, I'll double check anyways.
but it's not guaranteed
That's interesting. I wonder under which conditions it is guaranteed.
There are no conditions under which it is guaranteed. There are plenty of conditions in which it might happen, but the compiler knows best and does what it wants.