This article was previously published under Q198477
This article has been archived. It is offered "as is" and will no longer be updated.
NOTE: Microsoft Visual C++ .NET (2002) and Visual C++ .NET (2003) support both the managed code model that is provided by the .NET Framework and the unmanaged native Windows code model. The information in this article applies to unmanaged Visual C++ code only.
Use of the compiler switch /ZI (Program Data Base for Edit and Continue) may cause an access violation if you try to modify a text string.
Use one of the following workarounds:
In the sample below, change "char * ptr" to "char ptr".
Do not use the /ZI switch.
As per C++ Standard (188.8.131.52) the effect of attempting to modify a string literal is undefined.
By default the compiler switch /ZI (Program Data Base for Edit and Continue) uses the compiler switch /GF.
The /GF option enables the compiler to pool strings and place them in read-only memory. By placing the strings in read-only memory, the operating system does not need to swap that portion of memory. Instead, it can read the strings back from the image file. It is a good idea to do this as it saves pages of memory from being written to and therefore reduces the working set used by the application. In addition, it allows those pages to be shared between multiple instances of the process that use that image file (.exe or .dll file), further reducing total memory usage in the entire system. Strings placed in read-only memory cannot be modified; if you try to modify them, you will see an Application Error dialog box.
The following code when executed after compile produces an access violation.
Microsoft Visual C++ 6.0 Enterprise Edition, Microsoft Visual C++ 6.0 Professional Edition, Microsoft Visual C++, 32-bit Learning Edition 6.0, Microsoft Visual C++ .NET 2002 Standard Edition, Microsoft Visual C++ .NET 2003 Standard Edition