This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Function pointer question
- From: Ian Lance Taylor <iant at google dot com>
- To: Aaron Abassi <rap dot paradigm at gmail dot com>
- Cc: gcc at gcc dot gnu dot org
- Date: Sun, 17 Apr 2011 21:33:09 -0700
- Subject: Re: Function pointer question
- References: <BANLkTinE2Ho6QC4ix0dUY7G+hh8O3DzRoQ@mail.gmail.com>
Aaron Abassi <rap.paradigm@gmail.com> 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