Provide a hierarchically organized set of identifers. More...
Macros | |
#define | UNIQ(POS0, POS1) |
Refer to the POS1 -last unique identifier recently created. | |
#define | UNIQ_DOWN |
Move down one level in the hierarchy of unique identifiers. | |
#define | UNIQ_NEW |
Create and return a new unique identifier. | |
#define | UNIQ_UP |
Move up one level in the hierarchy of unique identifiers. | |
Interal macros | |
| |
#define | ELLIPSIS_UNIQUE0(NAME, CURRENT, POS0, POS1, ...) |
#define | ELLIPSIS_UNIQUE1(NAME, LEVEL, POS, ...) |
#define | ELLIPSIS_UNIQUE2(NAME, LEVEL, LAST, POS, ...) |
#define | ELLIPSIS_UNIQUE3(NAME, LEVEL, NUMBER) |
#define | ELLIPSIS_UNIQUE_LEVEL |
#define | ELLIPSIS_UNIQUE_NAME() |
#define | ELLIPSIS_UNIQUE_NEW(NAME, LEVEL) |
#define | ELLIPSIS_UNIQUE_UPDOWN(...) |
#define | ELLIPSIS_UNIQUE_UPDOWN1(...) |
Provide a hierarchically organized set of identifers.
This provides a set of macros prefixed with UNIQ
that expand and manage unique identifiers. (For using other another name than UNIQ
, see below.) Central are macros UNIQ_NEW
and UNIQ
that create respectively refer to an identifier.
Note that here UNIQ
needs parenthesis for the invokation and receives 0, 1, or 2 arguments. The above expands to something similar as the following
Obivously here the concrete names that are chosen depend on the context where this code would be found. You should not try to recover such names manually.
The first argument to UNIQ
indicates to which of the unique idenfier it refers: 0, the default, refers to the last identifer created with UNIQ_NEW
(here the variable initialized with the value 6
), 1 to the one before (here the variable initialized with the value 5
).
So the above example should print the values 6 5
in that order.
Two additional macros, UNIQ_UP
and UNIQ_DOWN
, add a hierarchical aspect, namely nesting levels for identifiers. To see that consider a macro SWAPEM(A, B)
with the following expansion:
Here we use UNIQ_UP
to move one "level" up in the hierarchy if identifiers. This and the UNIQ_DOWN
at the end have no visual effect on the code, only that they steps one level up or down in the identifier hierarchy. To see that in context let's amend our example from above by adding an invokation of SWAPEM
.
The expansion would be looking similar to the following:
So here the expansion of the three lines that we had before has not changed at all; in the printf
call we can easily refer to the identifiers as we did before without needing to worry about what effects the invokation of SWAPEM
might have caused.
In contrast to that the call to SWAPEM
itself sees a new set of names for its variables, here identifiers starting with UNIQ_ID_2_
, and so the variables defined there are in no conflict with the identifiers in the surrounding scope.
As a result of this invokation, the contents of the two variables is swapped and the two values would be 5 6
, inverted compared to what we had seen above.
UNIQ
has an optional second parameter that refers to the level in which the identifier is sought. As for the first paremeter, 0
, the default, refers to the current level, 1
refers to one level down and so on.
Typically you would include this feature with a directive such as
This provides you with a set of macros as described above that have names starting with UNIQ
. If you wand to change that, you may bind the macro UNIQUE_NAME
to a prefix of your liking. For example
creates an alternative set of macros LABEL
, LABEL_NEW
, LABEL_UP
and LABEL_DOWN
that can be used in a similar way, but which result in identifiers that use "LABEL" instead of "UNIQ".
{}
scope (C only) #define ELLIPSIS_UNIQUE0 | ( | NAME, | |
CURRENT, | |||
POS0, | |||
POS1, | |||
... | |||
) |
#define ELLIPSIS_UNIQUE1 | ( | NAME, | |
LEVEL, | |||
POS, | |||
... | |||
) |
#define ELLIPSIS_UNIQUE2 | ( | NAME, | |
LEVEL, | |||
LAST, | |||
POS, | |||
... | |||
) |
#define ELLIPSIS_UNIQUE3 | ( | NAME, | |
LEVEL, | |||
NUMBER | |||
) |
#define ELLIPSIS_UNIQUE_LEVEL |
#define ELLIPSIS_UNIQUE_NAME | ( | ) |
#define ELLIPSIS_UNIQUE_NEW | ( | NAME, | |
LEVEL | |||
) |
#define ELLIPSIS_UNIQUE_UPDOWN | ( | ... | ) |
#define ELLIPSIS_UNIQUE_UPDOWN1 | ( | ... | ) |
#define UNIQ | ( | POS0, | |
POS1 | |||
) |
Refer to the POS1
-last unique identifier recently created.
The second argument may chose identifiers from different levels, 0
is the current level, 1
is one level down and so on.
If omitted both parameters default to 0
.
#define UNIQ_DOWN |
Move down one level in the hierarchy of unique identifiers.
Otherwise this macro has no visible effect.
#define UNIQ_NEW |
Create and return a new unique identifier.
#define UNIQ_UP |
Move up one level in the hierarchy of unique identifiers.
Otherwise this macro has no visible effect.