Hello,

So I've got a code where I'm wanting to make sure that there is nothing in this class variable "finalgrid". To do this I've got an if statement:

if(canvas->finalgrid)
OR
if(finalgrid)

Sorry for the confusion with the two statements, but I'm working on modifying one project to fit in another, (wrapping a glui project with wxWidgets). Unfortunately, the gluiproject without the canvas-> works properly and appears to be the same as the modified project, but when I put a break point at the if statement, this is what I see as a discrepancy.

canvas->finalgrid = 0xcdcdcdcd {BoundaryVertices=??? GridSquareVertices=??? GridSquareFlag=??? ...}

finalgrid = 0x00000000 {BoundaryVertices=??? GridSquareVertices=??? GridSquareFlag=??? ...}

I didn't think that with either of their contents, either should enter the if statement, but actually the canvas->finalgrid does enter it, and I'm guessing it might have something to do with 0xcdcdcdcd but I'm not sure. The finalgrid does not enter the if statement, and I'm not sure why its address is 0x0000000.

If anyone can shed some light onto this situation, I would be delighted! Thanks in advance and if I didn't make anything clear enough please let me know.

Note: these were instantiated as dynamic instance of another class

GridGeneration *finalgrid;

I'm not initializing it, so I'm not wanting anything to be in the variable, meaning I do NOT want it to enter that if statement, but unfortunately it is in the case of (canvas->finalgrid).

When you compile programs with Microsoft compilers in DEBUG mode the compiler will fill pointer addresses with that value 0xcdcdcdcd or some such value like that to indicate that address has not been used. if you code something like this char *ptr = 0; then the address will be 0x0000, as expected, but char* ptr the address is set to 0xcdcdcdcd.

If you are going to test the validity of that pointer, then declare it like this: GridGeneration *finalgrid = 0; or GridGeneration *finalgrid = NULL; , both are equivalent.

Well that makes perfect sense, but could you explain why even without being initialized, just the filled pointer address it was entering the loop?

Or does it just do that because?

And thanks for the solve :)

This question has already been answered. Start a new discussion instead.