The arguments of a function call are used to initialize the parameters of the function definition. Array expressions and C function designators as arguments are converted to pointers before the call.
Integral and floating-point promotions will first be done to the values of the arguments before the function is called.
The type of an argument is checked against the type of the corresponding parameter in the function declaration. The size expressions of each variably modified parameter are evaluated on entry to the function. All standard and user-defined type conversions are applied as necessary. The value of each argument expression is converted to the type of the corresponding parameter as if by assignment.
For example:
#include <stdio.h> #include <math.h> /* Declaration */ extern double root(double, double); /* Definition */ double root(double value, double base) { double temp = exp(log(value)/base); return temp; } int main(void) { int value = 144; int base = 2; printf("The root is: %f\n", root(value, base)); return 0; }
The output is The root is: 12.000000
In the above example, because the function root is expecting arguments of type double, the two int arguments value and base are implicitly converted to type double when the function is called.
The order in which arguments are evaluated and passed to the function is implementation-defined. For example, the following sequence of statements calls the function tester:
int x; x = 1; tester(x++, x);
The call to tester in the example may produce different results on different compilers. Depending on the implementation, x++ may be evaluated first or x may be evaluated first. To avoid the ambiguity and have x++ evaluated first, replace the preceding sequence of statements with the following:
int x, y; x = 1; y = x++; tester(y, x);
The remainder of this section pertains only to C ++.
If a nonstatic class member function is passed as an argument, the argument is converted to a pointer to member.
If a function parameter is a variable length array, the array dimensions other than the leftmost dimension distinguish the overload set for that function.
If a class has a destructor or a copy constructor that does more than a bitwise copy, passing a class object by value results in the construction of a temporary that is actually passed by reference.
It is an error when a function argument is a class object and all of the following properties hold:
Related References