Here is a program that uses an inline function to compute and return the absolute value of its input argument.
# include
inline int abs(int x)
{
return x <0? -x : x ;
}
void main( )
{
for (int i=-2 ; i<2 ; ++i)
{
int value = abs(i) ;
printf ("Absolute value of %+d = %+d\n",i, value);
}
}
The output is:
Absolute value of -2 =+2
Absolute value of -1 =+1
Absolute value of +0 =+0
Absolute value of +1 =+1
When the call to the abs ( ) function is encountered, the compiler, instead of making a function call, generates this assembly code.