Original Post
Is there any chance of function calls via a pointer will be inlined and optimised away? Hypothetically speaking? I tried this simple contrived example in MSVC++ 2005 EE, Release, inlining Any Suitable, Link Time Code Generation (compiler+linker). The inline depth should be the default 254, but I manually set in anyway: I'm trying to make things real simple here for the compiler. const function pointers to a locally declared function. It's interesting that the LocalPointer gets resolved to a regular function call, but then the compiler doesn't make the next step of inlining that (simple) function call. The call itself resolves to a mov eax,1200 ret :S Presumably there's greater difficulty involved in inlining the GlobalPointer, because the compiler has more trouble in general, determining if the pointer is safe/const?
#pragma inline_depth(254)
inline int SimpleFunction ()
{
return 1200;
}
typedef int (*SimpleFunctionPointerType) ();
// const there should make the function pointer const, I believe
SimpleFunctionPointerType const SimpleFunctionGlobalPointer (&SimpleFunction);
int main ()
{
int k = 0;
// const here should make the function pointer const, I believe
SimpleFunctionPointerType const SimpleFunctionLocalPointer (&SimpleFunction);
k += SimpleFunctionLocalPointer ();
004012AE call SimpleFunction (401250h)
004012B3 add eax,edi
004012B5 add esi,eax
k += SimpleFunctionGlobalPointer ();
004012B7 call dword ptr ds:[4021C8h]
cout << k;
}