Reprint please specify the source:
Http://www.cnblogs.com/darkknightzh/p/5598091.html
The first two days of debugging program, there is a very painful problem, debug and release results inconsistent. Many on the web say that the variable is not initialized, but my side of the variable has been initialized.
Finally, check carefully, find the debug and release under the code results inconsistent. Extract and simplify the part of the code as follows:
intMatrixplusdiagvec (float* PMat,Const float* Pvec,intDim) { for(inti =0; I < Dim; ++i) {pmat[i* (Dim +1)] +=Pvec[i]; } return 0;}voidShowrowres (Const float* Data,intLen) { for(inti =0; i < Len; ++i) {cout<< I <<' '<< Data[i] <<Endl; }}intMain () {intnum = -; float* PA =New float[Num *num]; Memset (PA,0,sizeof(float) * num *num); float* PB =New float[Num *num]; for(inti =0; i < num; ++i) {Pb[i]= (i +1) *5; } Matrixplusdiagvec (PA, PB, num); Showrowres (PA, num); System ("Pause"); return 0;}
In fact, the simple code is to put elements of a vector on a diagonal matrix, but debug and release results are inconsistent. After calling Showrowres, because the first row of results is displayed, only the first element should be 0, and the others are 0. Debug under Normal, release the first 4 results are not correct.
Debug displays the first line with the following results:
Release shows the result of the first line as follows:
Release shows that line No. 234 is 0, showing the result of line 5th:
In the above program, float changed to int, the result of release is still not normal.
Later, the Matrixplusdiagvec function
Pmat[i * (Dim + 1)] + = Pvec[i];
Switch
Pmat[i * (Dim + 1)] = Pmat[i * (Dim + 1)] + pvec[i];
Or
Pmat[i * Dim + i] + = pvec[i];
or Pmat[i * (Dim + 1)] + = Pvec[i]; then add a cout,
or use vs2015 to compile the program,
The results are correct. I can't understand why, anyway.
Because I don't see disassembly code, I don't see it.
Then someone looked at the version of VS that I used, as follows:
Recommended Update to UPDATE5, after the update, there is no problem. As follows:
Therefore, guess the reason should be vs2013 I use the version of the bug bar.
So, if the program can not understand the debug and release why the result is inconsistent, then ... Well, update the IDE. This pot, only the IDE back.
Debug and release results are inconsistent in (original) vs