Can I embed functions used with function pointers?

#include <stdlib.h> inline int f0(int a) { return a*a; } inline int f1(int a) { return a*a*a; } int main() { int (*f)(int); f = rand()%2 ? f0 : f1; return f(rand()); } 

So, with gcc, the created asm file matches with or without the built-in. Same thing with any code with function pointers?

+6
source share
1 answer

Function pointers cannot be inlined unless their value is fully resolvable at compile time. Your case is not solvable.

In most cases, function pointers will never be inlined, even if the compiler can see which function is specified in the function.

+6
source

Source: https://habr.com/ru/post/896600/


All Articles