c++ - VS2010 C code - String pooling -


Under Code Accident in VS 2010 when you compile with the following flag and if you add / gf- or optimization If they remove the flag, then they are not accidental accident occurs on assembly code which translates 'if (path [i] ==' / ')'. I would like to understand the optimization that the compiler will come here and crash. Looking forward to some indicators.

- Kartik

cl.exe / MD / O2 test.c

/ / Test .c

  #include & lt; Stdio.h & gt; #include & lt; String.h & gt; Zero circuit path (four * paths, int buffies) {int i; Printf ("% p \ n", path); (I = 0; i & lt; strlen (path); i ++) {if (path [i] == '/') {path [i] = '\\'; }}} Int main () {const char * path = "testexport.prj"; Char * path1 = "testexport.prj"; Printf ("% p \ n", path); Printf ("% p \ n", path 1); Test path (path, 1024); }  

to modify the content of a string literal Trying invites unscheduled behavior.

with ISO C 99 ( section 6.4.5 / 6 )

It is reluctant whether these arrays are separated from their elements The appropriate value is If the program tries to modify such an array, then the behavior is unde fied

ISO C ++ - 98 ( Section 2.13.4 / 2 )

What is the definition of all string literals different (i.e., stored in non-overlapping objects) implementation Security has been effect of attempts to change a string is unclear.

Most implementations (including MSVC) are the result of your app crash.


Comments