in·con·sis·tent II
Again the Visual Studio C++ Debugger has proven to be a bit inconsistent and this time it’s with function addresses.Here is a small piece of code that simply prints the address of a function, nothing more:
#include <iostream>
using namespace std;
// just an empty function
void func()
{
}
int main(int argc, char* argv[])
{
// print out address of function
cout << “func = ” << hex << func << endl;
return 0;
}
Now, lets try to add a breakpoint to to the cout, and check the value that is about to be printed. This is what we see:

Ok, that looks fairly good. The function is located at 0×004114C0. But hey!, when we check the output that this line actually created we get this:
func = 004110AF
For the love of %#!%, what happened here?! Suddenly someone decided that the appropriate way to print out the number 004114C0 was to print 004110AF. And what address is the correct one. The address shown by the debugger or the one shown by the console?
To decide that, here is another example only involving the debugger:
#include <iostream>
using namespace std;
// just an empty function
void func()
{
}
int main(int argc, char* argv[])
{
// function pointer that points to func
void (*fptr)() = func;
return 0;
}
This code just declares a function pointer and makes it point to func. Rather simple, until we start debugging. First let us examine the address of func:

Again this looks fairly good. This time the address of func is 0×00411370. Then lets take a look at what value the function pointer holds. Any sane person (like me) would know that the function pointer points to func, thus their values should be equal. But does the debugger agree on this?

Nope, it doesn’t. Now, the function pointer points to 0×00411082 and not 0×00411370 as one would expect… so what’s up with that?
Maybe I’ll take the time to explain that some other time… now it’s time for a beer.












