开发者

Debug and release modes giving different outputs

I have a function in my program that outputs a data structure that consists of three doubles in two formats, one text and one binary.

When I run the program in debug and r开发者_JAVA技巧elease modes, I end up with different binary outputs but identical text outputs. What is going on?

Here is the binary output code:

void outputPoints(xyz* points, string description, int length, param parameters)
{

    stringstream index;
    index.str("");
    index << setw( 3 ) << setfill( '0' ) << parameters.stage;

    string outputName = parameters.baseFileName + " " + index.str() + " " + description + ".bin"; // create file name

    ofstream output; // create output object

    cout << "Output " << outputName.c_str() << "...";

    output.open(outputName.c_str(), std::ios::binary | std::ios::out); // open or create file for output
    output.write(reinterpret_cast<char*>(points), (sizeof(xyz) * length));
    output.close(); // close output object

    cout << "done" << endl;
}


The debug build usually initializes variables with some patterns. Usually data allocated has the content CDCD, deleted objects are overwritten with FEEE. The CDCD pattern is overwritten when you initialize your variables. The release build doesn't initiliaze with these patterns.

It's worth to check your program for uninitialized variables. You can define a Dump function that just prints the (fist few bytes of) the suspected variables.


I don't know whether you got a solution for your issue and I did not look at your code. I had the same issue because I was adding unsigned char and unsigned short and saving into unsigned short. I changed all variables to unsigned short and the issue was solved.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜