Could someone please explain the difference in how the 2 snippets of code are handled below? They definitely compile to different assembly code, but I'm trying to understand how the code might act differently. I understand that string literals are thrown into read only memory and are effectively static, but how does that differ from the explicit static below?
struct Obj1
{
void Foo()
{
const char* str( "hello" );
}
};
and
struct Obj2
{
void Foo()
{
static const char* str( "hello" );
}
};
See Question&Answers more detail:os