January 18, 2006
Why does VC not generate a warning if a const-string in non-const parameters...
One of the questions in newsgroups/forms which come up over-and-over is: Why does the following code generates an access vialolation?:
CreateProcess(NULL, _T(“my.exe”), NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi);And the answer is not very obvious… The second parameter of CreateProcess must be writable! And VC8 (7.1 also?) puts static (const) test literals into a read-only section. Therefor a write attempt to this string results in an access violation.
Now my qustion is: Why does the compiler not generate a warning if the “const” string is assigned to a non-const variable/paramater (LPTSTR)???
As a side effect of this: All examples in the MSDN are wrong if compiled with VC8!!!
Changing Environment Variables
Creating a Child Process with Redirected Input and Output
How to spawn console processes with redirected standard handles
The trackback url for this post is http://blog.kalmbachnet.de/bblog/trackback.php/62/
Posted 1 year, 11 months ago by Ullrich Praetz • • www • Reply
Comment Trackback URL : http://blog.kalmbachnet.de/bblog/trackback.php/62/356/
Posted 1 year, 11 months ago by Scherbina Vladimir • • www • Reply
Comment Trackback URL : http://blog.kalmbachnet.de/bblog/trackback.php/62/357/
Comments have now been turned off for this post