I was wondering if a function pointer pointing to an inline
function, will actually expand "inline" when the function pointer
is invoked.
#include <iostream>
#include <vector>
using namespace std;
const int MAX_FP_SIZE = 10;
typedef void (*fp)(int& i);
vector<fp> vfptr(0);
inline void incr_callback(int& i)
{
i++;
cout << "i is " << i << endl;
}
inline void decr_callback(int& i)
{
i--;
cout << "i is " << i << endl;
}
void
register_callback(fp fptr)
{
vfptr.push_back(fptr);
}
void
schedule_callbacks(void)
{
int i = 0;
vector<fp>::iterator iter;
fp tmp_fp;
cout << "i is " << i << endl;
for (iter = vfptr.begin(); iter != vfptr.end(); iter++) {
tmp_fp = *iter;
tmp_fp(i);
}
}
int
main(void)
{
register_callback(incr_callback);
register_callback(decr_callback);
schedule_callbacks();
}
In the piece of code above, I would actually like tmp_fp(i) to expand
inline. I understand that such optimization is hard to achieve, but
are there any compilers out there that can do this?
TIA,
Balbir
[ See
http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]