P99

◆ P99_ACALL

#define P99_ACALL (   ARR,
  N,
  TYPE 
)

Pass a pointer to an N dimensional array ARR to a function.

This is not supposed to be used directly but instead is for defining a macro interface to a function:

double dotproductFunc(P99_AARG(double const, A, 1),
P99_AARG(double const, B, 1));
#define dotproduct(VA, VB) \
dotproductFunc(P99_ACALL(VA, 1, double const), \
P99_ACALL(VB, 1, double const))
.
double Ar[5];
double Br[5];
.
double result = dotproduct(&Ar, &Br);

Here the expression with dotproduct in the last line will first result in a macro expansion that will place the pointers as well as the array sizes to a call of the function dotproductFunc.

If the argument N is omitted it will default to 1, indicating that the array is just one dimensional. If N is greater than 1, a list of the N lengths in the first N dimensions of ARR is passed to the function call.

TYPE can be omitted in which case no attempt to conform types will be made. Specifying TYPE is particularly helpful if the type is qualified, that is it has a const or volatile qualification as in the example above. If you don't use this macro, ensuring constness of multidimensional arrays is particularly tedious.

To be more precise, the three argument form asserts that pointers to the elements of the matrix are assignment compatible to pointers of the indicated type. Then we do the cast to the pointer to matrix type that would otherwise be dangerous and could hide incompatibilities.

See also
P99_AARG
Remarks
argument 0 maybe evaluated several times for its type but only once for its value
argument 1 must expand to a decimal number
argument 2 should correspond to a type that is not a VLA.

Definition at line 725 of file p99_for.h.

P99_AARG
#define P99_AARG(TYPE, NAME, DIM, VAR)
Declare a pointer to array function argument of basetype TYPE, with name NAME, dimension DIM and nami...
Definition: p99_for.h:750