Aaron Abassi <[email protected]> writes:
> I was wondering if someone could answer a question regarding the
> feasibility (this is not a request for changes to GCC) of constant
> function pointer inlining. This obviously would require a compiler to
> do an N-depth analysis of pointer assignments to confirm that the
> value could not change (constant all the way back the address'
> origin).
>
> My question is; theoretically is this possible? (I'm obviously not a
> compiler programmer)
Assuming I understand you correctly (it always helps to provide a code
example): yes, it is feasible.
gcc already does it in some cases. E.g.:
inline int f(int i) { return i; }
int g(int (*pfn)(int), int i) {
return (*pfn)(i);
}
int h(int i) {
return g(f, i);
}
When compiled with -O2, f will be inlined into h.
Ian