Formal argument
What actually happens during an inline expansion?
1. In general, each formal argument is replaced with its corresponding actual argument.
1. In general, each formal argument is replaced with its corresponding actual argument.
2. If the actual argument exhibits a side effect, temporary objects are introduced.
3. If the actual argument is a constant expression, it is evaluated prior to its substitution.
Local variables
In general, each local variable within the inline function must be introduced into the enclosing block of the call as a uniquely named variable. If the inline function is expanded multiple times within one expression, each expansion is likely to required its own set of the local variables.
inline int min(int i, int j)
{
int minval = i
{
int minval = i
return minval;
}
}
{
int local_var;
int minval;
//...
minval = min(val1, val2);
}
will be transformed into:
{
int local_var;
int minval;
//mangled inline local variable
int __min_lv_minval;
minval = (__min_lv_minval = val1
}
Summary: arguments with side effects, multiple calls within a single expression, and multiple local variables within the inline itself can all create temporaries that the compiler may or may not be able to remove.
No comments:
Post a Comment