P99

◆ P99_MAC_ARGS

#define P99_MAC_ARGS (   ...)
Value:
P99_FOR(, P99_NARG(__VA_ARGS__), P00_SEP, P00_MAC_ARGS_REAL0, __VA_ARGS__); \
P99_FOR(, P99_NARG(__VA_ARGS__), P00_SEP, P00_MAC_ARGS_REAL1, __VA_ARGS__)

Declare macro parameters as local variables as if the macro were declared as a type generic inline function.

Remarks
This uses the typeof extension implemented by gcc.

This receives parenthesized pairs of name and value that are to be promoted as local variables inside a macro expansion. Use this as follows:

#define atomic_fetch_add_conditional(OBJP, OPERAND) \
({ \
P99_MAC_ARGS((p00_objp, OBJP), (p00_op, OPERAND)); \
... \
})
Remarks
The corresponding local variables have exactly the type of the expressions that are passed as the 2nd element in each pair.

This achieves several objectives

  • Each macro parameter is evaluated exactly once.
  • The values of the macro parameters are accessible through an ordinary identifier.
  • Even if a variable with one of the names is passed through a macro parameter (e.g by calling atomic_fetch_add_conditional(p00_op->next, 23)) there will be no conflict.

This is done by evaluating all macro arguments first, as it would be for a function call, and then assigning it to fresh variables.

Remarks
argument 0 maybe evaluated several times for its type but only once for its value
argument 1 maybe evaluated several times for its type but only once for its value
argument 2 maybe evaluated several times for its type but only once for its value

Definition at line 1236 of file p99_for.h.

P99_NARG
#define P99_NARG(...)
Return the length of the variable length argument list, where an empty argument list is considered to...
Definition: p99_args.h:117
P99_FOR
#define P99_FOR(NAME, N, OP, FUNC,...)
A preprocessor pseudo iterator.
Definition: p99_for.h:92