假设我有一个函数,
static inline int res( int x )
{
/** total() is a large func */
int processedPkts = total();
return ( processedPkts + x);
}
int total()
{
/** Where the function total() does lot of processing,counting no of packets
or say, it has many lines of code */
}
Run Code Online (Sandbox Code Playgroud)
所以,我的问题是,我可以使用静态内联res()函数来调用更大的函数吗?
根据我对为什么/何时使用内联的理解,
它鼓励编译器将函数构建到使用它的代码中(通常是为了提高执行速度)。
静态内联通常与小函数一起使用,这些函数在调用例程中比使用调用机制更好地完成,仅仅是因为它们如此短且快,以至于实际执行它们比调用单独的副本更好。
因此,在汇编级别,total()函数不受静态内联影响(使用常规调用机制),因此建议对res()?使用静态内联。