连续相同的"printf"调用产生不同的输出

use*_*885 1 c io double printf

我连续调用printf函数,第一个printf写入必须写入的内容,第二个printf只写无效值,我猜一些错误.

"LOC"的类型由我定义,变量"i"在调用后不会改变.我检查了双倍的printf和我给它的值之间的任何差异.

i=2;
printf("x = %f,y = %f,z = %f\n",(*LOC)[0].ProjectionPoints[i].X,(*LOC)[0].ProjectionPoints[i].Y,(*LOC)[0].ProjectionPoints[i].Z); /* Prints perfectly */
printf("x = %f,y = %f,z = %f\n",(*LOC)[0].ProjectionPoints[i].X,(*LOC)[0].ProjectionPoints[i].Y,(*LOC)[0].ProjectionPoints[i].Z); /* Shows some errors and values are "0" */
Run Code Online (Sandbox Code Playgroud)

首先printf写道

x = -10.000000,y = -8.000000,z = -10.000000
Run Code Online (Sandbox Code Playgroud)

第二个printf写道

x = 0.000000,y = 0.000000,z = -1.#QNAN0
Run Code Online (Sandbox Code Playgroud)

即使定义变量const也不会改变任何东西.

我的编译器是: MS Visual C++ 2012

看完评论后;

typedef struct {
P3C_Point *ProjectionPoints;
uint Distance,LayerID,NumberOfPoints,ModelID;} P3C_LayerOnCurtain;
/* and */
P3C_LayerOnCurtain **LOC = P3C_Compile(Stream);
/* when I try printf in P3C_Compile it has no problems */
Run Code Online (Sandbox Code Playgroud)

我在返回值之前做了测试,在函数中产生"LOC"是完美的printf.

答案/解决方案;

 P3C_LayerOnCurtain *LOC = *P3C_Compile(Stream);
Run Code Online (Sandbox Code Playgroud)

Med*_*noc 5

最可能的原因是LOC或者(*LOC[0].ProjectionPoints)是指向返回它们的函数的局部变量的指针.

如果是这样,它们将被printf局部变量覆盖.