in·con·sis·tent
I was debugging this small application (not the listed one, that’s just an oversimplified example - mine was quite bigger) when found something horrific. Visual C++ 2005 was messing up big time, both misreading my code and calling the wrong set of functions - or so I thought. The truth was just a matter of inconsistency.
Take a look at this simple code:
#include <iostream>__declspec(noinline) void func1()
{
std::cout << std::endl;
}
__declspec(noinline) void func2()
{
std::cout << std::endl;
}
int main(int argc, char* argv[])
{
func1();
func2();
return 0;
}
Now, if you make an optimized release build of this code, the output should be something like this:
//int main(char* argv[], int argc)
//{
// func1();
00401020 call func1 (401000h)
// func2();00401025 call func1 (401000h)
// return 0;
0040102A xor eax,eax
//}
0040102C ret
Here you can see the effect of the optimized code. The compiler figured out on its own that both function func1 and func2 is similar, thus silently reusing func1 (and throwing away func2).
But when you step your way into one of the function calls you get to a point where the debugger shows this:
//__declspec(noinline) void func2()
//{
// cout << endl;
00401000 mov eax,dword ptr [__imp_std::endl (40203Ch)]
00401005 mov ecx,dword ptr [__imp_std::cout (402040h)]
0040100B push eax
0040100C call dword ptr [__imp_std::basic_ostream<:char_traits >::operator<< (402038h)]
//}
00401012 ret
Here the compiler has decided that the function to use is func2 (and that it assumedly has thrown away func1). Now, are there any reason for this name inconsistency or is it just to confuse some poor developer already kneedeep in a corrupt stack?












