我连续调用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" */
第一个printf写
x = -10.000000,y = -8.000000,z = -10.000000
第二个printf写
x = 0.000000,y = 0.000000,z = -1.#QNAN0
即使定义变量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 */
我做了测试,然后我返回值,在函数中产生“LOC”是printf完美。
Answer/Solution;
P3C_LayerOnCurtain *LOC = *P3C_Compile(Stream);
出租车你构建一个测试用例吗? –
X,Y,Z如何声明? – alk
(你能告诉我们LOC的定义吗?) –