Difference between static const char* and const char*.
Posted
by Will MacDonagh
on Stack Overflow
See other posts from Stack Overflow
or by Will MacDonagh
Published on 2010-05-28T12:20:28Z
Indexed on
2010/05/28
12:22 UTC
Read the original article
Hit count: 257
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 Bar()
{
static const char* str( "hello" );
}
};
© Stack Overflow or respective owner