Reputation: 1103
My code is:
//fun FUNCTION
void fun(int D1, int D2, int arr[D1][D2])
{
//FUNCTION BODY
}
//MAIN FUNCTION
int D1, D2;
int arr[][3]=//VALUES
D2=sizeof(arr[0])/sizeof(a[0][0]);
D1=sizeof(arr)/sizeof(a[0]);
fun(D1,D2,arr);
How would compiler know the dimensions of array arr
in function fun if the order of parameters of function is uncertain?
Upvotes: 6
Views: 107
Reputation: 222447
The C standard does not specify the order of evaluation of arguments. However, all arguments are evaluated before the function is called. Per C 2018 6.5.2.2 10 (which discusses function calls):
There is a sequence point after the evaluations of the function designator and the actual arguments but before the actual call.
Thus, when execution of the called function begins, all arguments have been evaluated, so their values are known. Then the size expressions of variably modified parameters are evaluated, per 6.9.1 10 (which discusses function definitions):
On entry to the function, the size expressions of each variably modified parameter are evaluated and the value of each argument expression is converted to the type of the corresponding parameter as if by assignment.
(Note that arguments are what a caller passes to a function, and parameters are the objects declared as part of the function declaration or definition that acquire values on entry to the function.)
Upvotes: 3