Why does a pointer change itself during function transition?

c++, pointers

Solution

If you are trying to debug optimized code in for example Visual Studio, you cannot always rely on the debugger properly showing the values of variables - especially not if the variable is unused so that the compiler probably optimizes it away.

Try running this instead:

bool Func(PFSPARA pfspara)
{
    printf("%x\n", pfspara);
    return false;
}

Problem

In the following case I'm calling a `Func` with pointer passed to it, but in the called function, the parameter shows the pointer value as something totally bogus. Something like below. ``` bool flag = Func(pfspara);--> pfspara = 0x0091d910 bool Func(PFSPARA pfspara) --> pfspara = 0x00000005 { return false; } ``` Why does `pfspara` change to some bogus pointer? I can't reproduce the problem in debug, only in production. Thanks.

Original source