c - Can gcc inline an indirect function call through a constant array of function pointers? -


let's have code:

inline int func_2 (int a, int b) {   return time() + * b; }  int main (void) {   int x = (int (*[])(int, int)){func_1, func_2, func_3}[1](6, 7); } 

can gcc somehow tricked inline indirect calls func_*?

after compiling code -o2 , -o3, still spot call func_2 instruction in assembly output.

i know hairy expression can converted bulky switch statement inlined calls each case, prefer former compactness.

if not hurt allocate space in data segment, can try this:

static int func_2 (int a, int b) {     return time() + * b; }  static int (* const ftab[])(int,int) = {func_1, func_2, func_3};  int foo (void) {     return ftab[1](6,7); } 

my gcc 4.4.5 correctly inlines function -o2.

the aggregate initializer inside code of function not forward constant expect, don't know wheter it's gcc bug or our misunderstanding of c rule.


Comments

Popular posts from this blog

linux - Mailx and Gmail nss config dir -

c# - Is it possible to remove an existing registration from Autofac container builder? -

php - Mysql PK and FK char(36) vs int(10) -