I have the following piece of code.
#include <iostream>
using namespace std;
inline void inlinefunc() { cout << "hello" << endl; }
void func() { cout << "hello" << endl; }
bool isInlineFunc(void (*f)()) { return (f == inlinefunc); }
void print(void (*f)()) {
cout << (isInlineFunc(f)?"inline - ":"normal -");
f();
}
int main() {
void (*f)();
f = inlinefunc;
print(f);
f = func;
print(f);
}
How do I generically write isInlineFunc?
What do you mean generically? Do you want to have a function that tells you if another function is declared inline? That can't be done.
Also note that by taking the address of an inline function, the implementation is forced to actually have an out of line implementation of the function.
You don't.
The compiler is basically allowed to do whatever it wants with regards to inlining functions. A function can be inlined in one place and not inlined in another place.
If you're thinking about this, you're probably prematurely optimizing something.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With