P99

◆ P99_DO

#define P99_DO (   TYPE,
  VAR,
  LOW,
  LEN,
  INCR 
)    for(;;)

A fortran like do-loop with bounds that are fixed at the beginning.

Parameters
TYPEis the type of the control variable. It must be an arithmetic type.
VARis the name of the control variable. It is not mutable inside the loop, as if it were declared TYPE const VAR.
LOWis the start value of VAR for the first iteration. Only evaluated once before all iterations. Must be assignment compatible to type TYPE.
LENis the length of the iteration and is non-inclusive. Only evaluated once before all iterations. Must be assignment compatible to type TYPE.
INCRis the increment of VAR after each iteration. Only evaluated once before all iterations. INCR defaults to 1 if omitted. Must be assignment compatible to type TYPE.
P99_DO(size_t, i, a, n, inc) {
A[i] *= B[i-1]
}

would expand to something similar to

for (size_t i = a; i < (a + n); i += inc) {
A[i] *= B[i-1]
}

only that

  • the bounds of the loop (involving a and n) and the increment inc are fixed once when entering this construct
  • the loop variable i is not modifiable within the block
Warning
Placing a #pragma directive directly in front of P99_DO will not work because of syntactic restrictions. Use P99_PRAGMA_DO instead.
See also
P99_PARALLEL_DO for a parallel variant of this
P99_PRAGMA_DO for a variant of this that can be controlled with an arbitrary #pragma directive.
Examples
test-p99-pow.c.

Definition at line 882 of file p99_for.h.

P99_DO
#define P99_DO(TYPE, VAR, LOW, LEN, INCR)
A fortran like do-loop with bounds that are fixed at the beginning.
Definition: p99_for.h:882
i
P00_CLAUSE2 i(_Pragma("weak p00_getopt_comp"))(_Pragma("weak p00_getopt_comp