A multi-index for
loop.
Given the names of N
identifiers after NAME, NAME must correspond to an array of lengths with dimension at least N
.
For N
= 3 this could e.g be
size_t const D[] = { 3, 4, 7 };
Then, the macro in the following
A[i0][i1][i2] *= B[i0][i1][i2]
}
would expand to something similar to
for (size_t i0 = 0; i0 < D[0]; ++i0)
for (size_t i1 = 0; i1 < D[1]; ++i1)
for (size_t i2 = 0; i2 < D[2]; ++i2) {
A[i0][i1][i2] *= B[i0][i1][i2]
}
only that
- the bounds of the loops (involving
D
[0], D
[1] and D
[2]) are fixed once when entering this construct
- the loop variables
i0
, i1
and i2
are not modifiable within the block
- See also
- P99_PARALLEL_FORALL for a variant that uses OpenMp to parallelize the loop.
-
P99_DO for a simple fortran like iteration
-
P99_CDIM for a macro that computes the absolute position of an index N-tuple in a multi-dimensional array.
- Warning
- argument 0 may be evaluated multiple times
- Examples
- test-p99-pow.c.
Definition at line 956 of file p99_for.h.