P99

◆ P99_UNIQ

#define P99_UNIQ (   ...)    P99_IF_EMPTY(__VA_ARGS__)(P99_LINEID(P00_UNIQ, uniq))(P99_LINEID(P00_UNIQ, uniq, __VA_ARGS__))

An identifier token that is intended to be unique in this compilation unit.

This uses different line numbers in an include hierarchy to disambiguate, and, if available, the non-standard macro __COUNTER__.

The argument may contain a token that is appended to the id.

If during an individual compilation there is a conflict because this macro is used in lines with exactly the same LINE number, and __COUNTER__ is not available you'd have to include the file "p99_id.h" once more in one of the corresponding header files.

If you need the same unique identifier at several places in the same macro you'd have to cascade as in the following example:

#define MY_DO(ID, START, STOP, INC) MY_DO_(ID, P99_UNIQ(n), P99_UNIQ(p), (START), (STOP), (INC))
#define MY_DO_(ID, NU, PU, START, STOP, INC) for (unsigned ID = START, NU = STOP, PU = INC; ID < NU; ID += PU)
MY_DO(i, 0, strlen(filename), 1)
printf("%c-", filename[i]);

This would expand to

for (unsigned ID = 0, crude_n = strlen(filename), crude_p = 1; i < crude_n; i += crude_p)
printf("%c-", filename[i]);

Here, in the top most expansion of MY_DO two identifiers are generated and passed along as arguments of MY_DO_. (The "names" crude_n or crude_p only stand for some crude unique identifier you don't really want to know.)

The effect here is that the generated for loop has three local variables, that are initialized to the three arguments of MY_DO. By this, this macro can guarantee that the loop bounds are only evaluated once and that the number of iterations that is performed is known on entry to the loop.

Definition at line 197 of file p99_id.h.

i
P00_CLAUSE2 i(_Pragma("weak p00_getopt_comp"))(_Pragma("weak p00_getopt_comp