Reputation: 51
I call printf function consecutively and first printf writes what it must write, second printf just writes invalid values and I guess some errors.
Type of "LOC" is defined by me and variable "i" doesn't change after callings. I checked double for any discrepancy between printf and values I give it.
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" */
First printf writes
x = -10.000000,y = -8.000000,z = -10.000000
Second printf writes
x = 0.000000,y = 0.000000,z = -1.#QNAN0
Even defining variables as const
isn't change anything.
My compiler is: MS Visual C++ 2012
After I read comments;
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 */
I made test before I return value, in function produces "LOC" is printf perfectly.
Answer/Solution;
P3C_LayerOnCurtain *LOC = *P3C_Compile(Stream);
Upvotes: 1
Views: 447
Reputation: 6608
The most probable cause would be that LOC
or (*LOC[0].ProjectionPoints)
are pointers to a local variable of a function that returned them.
If so, they would be overwritten by printf
's local variables.
Upvotes: 5