See the following code:
Char g_array [] = "ABCD ";
Const char * g_pstring = "ABCD ";
Int main (INT argc, char * argv [], char * envp [])
{
G_array [0] = 'F ';
(Char *) g_pstring) [0] = 'F ';
Return 0;
}
An exception occurs at (char *) g_pstring) [0] = 'F';. Therefore, for constant strings, the compiler not only speaks during compilation
Legal
Check
,
It will automatically include
Set "read-only" protection for memory blocks.
Let's look at the following code:
Char * g_pstring = "ABCD ";
Int main (INT argc, char * argv [], char * envp [])
{
G_pstring [0] = 'F ';
Return 0;
}
You will also find exceptions at g_pstring [0] = 'F';, because strings are declared as constant strings in this way, the compiler will
Set "read-only" protection.
Supplement
2008-5-29
The compiler is only placed in the read-only data segment (. RDATA) in the debug version. For the release version, it is placed in the writable data segment (. Data). Therefore, there is no exception in rewriting the data in the release version. (This sentence has not been verified. Ant ~ Comment)