Predefined macros for all languages. More...
Macros | |
#define | ∷ __UNIT__∷ |
#define | ∷ __PARENT_UNIT__∷ |
#define | __COMPACT__(X, …) __MAP__(__EVALUATE__, X) |
Expand all arguments and remove whitespace surrounding them. | |
#define | __CONCAT__(…) |
evaluate and then concatenate up to 10 arguments | |
#define | __EXPAND__(…) __VA_ARGS__ |
expand the arguments | |
#define | __EXPAND_BIN__(…) __EVALUATE_BIN__(__VA_ARGS__) |
expand all the arguments, evaluate the resulting integer expression and produce a binary literal | |
#define | __EXPAND_BIN_U__(…) __CONCAT__(__EXPAND_BIN__(__VA_ARGS__), U) |
expand all the arguments, evaluate the resulting integer expression and produce a binary literal | |
#define | __EXPAND_COMMAS__(…) __EXPAND_DEC__(__COMMAS__(__VA_ARGS__)) |
expand all the arguments and count the number of toplevel commas in the resulting list | |
#define | __EXPAND_DEC__(…) __EVALUATE_DEC__(__VA_ARGS__) |
expand all the arguments, evaluate the resulting integer expression and produce a decimal literal | |
#define | __EXPAND_DEC_U__(…) __CONCAT__(__EXPAND_DEC__(__VA_ARGS__), U) |
expand all the arguments, evaluate the resulting integer expression and produce a decimal literal | |
#define | __EXPAND_EMPTY__(…) __EMPTY__(__VA_ARGS__) |
expand all the arguments and see if the result is empty | |
#define | __EXPAND_ERROR__(...) __ERROR__(__VA_ARGS__) |
Evaluate the __VA_ARGS__ , use them as an error message and abord compilation. | |
#define | __EXPAND_HEX__(…) __EVALUATE_HEX__(__VA_ARGS__) |
expand all the arguments, evaluate the resulting integer expression and produce a hexadecimal literal | |
#define | __EXPAND_HEX_U__(…) __CONCAT__(__EXPAND_HEX__(__VA_ARGS__), U) |
expand all the arguments, evaluate the resulting integer expression and produce a hexadecimal literal | |
#define | __EXPAND_OCT__(…) __EVALUATE_OCT__(__VA_ARGS__) |
expand all the arguments, evaluate the resulting integer expression and produce a octal literal | |
#define | __EXPAND_OCT_U__(…) __CONCAT__(__EXPAND_OCT__(__VA_ARGS__), U) |
expand all the arguments, evaluate the resulting integer expression and produce a octal literal | |
#define | __EXPAND_STRINGIFY__(…) __STRINGIFY__(__VA_ARGS__) |
expand all the arguments and put the result into one string | |
#define | __MAP__(F, …) __FREEZE__(F)(__VA_ARGS__)__FREEZE__(__VA_OPT__)(, )__FREEZE__(__VA_TAIL__)() |
Construct the body of a macro mapping F over all variadic arguments. | |
#define | __NARGS__(…) __EXPAND_DEC__(__COMMAS__(__VA_ARGS__) + ¬__EMPTY__(__VA_ARGS__)) |
expand all the arguments and count the number of items in the resulting list | |
#define | __ONE__ __EXPAND_DEC__(1) |
A predefined and pre-evaluated 1 | |
#define | __PARENT_UNIT__ |
A pseudo-macro that resolves to the name of the current parent unit. | |
#define | __STDC_EMBED_EMPTY__ __EXPAND_DEC__(2) |
A predefined and pre-evaluated value as required by the C standard. | |
#define | __STDC_EMBED_FOUND__ __EXPAND_DEC__(1) |
A predefined and pre-evaluated value as required by the C standard. | |
#define | __STDC_EMBED_NOT_FOUND__ __EXPAND_DEC__(0) |
A predefined and pre-evaluated value as required by the C standard. | |
#define | __STRINGIFY__(…) ⌗__VA_ARGS__ |
#define | __STRINGS__(X, …) __MAP__(__STRINGIFY__, X) |
create a list of strings formed from all the arguments after they are expanded | |
#define | __SUBUNIT__(NAME) |
A pseudo-macro that resolves to a name that is composed with the current parent unit name and NAME . | |
#define | __UGLIFY__(X) __ ⨝ X ⨝ __ |
add two leading and trailing underscores to the identifier X | |
#define | __UNIT__ |
A pseudo-macro that resolves to the name associated with the current translation unit. | |
#define | __UNLIST__(X, …) X __VA_TAIL__() |
Expand all arguments and remove commas between them. | |
#define | __VA_OPT__ __VA_OPT__ |
A pseudo macro that cannot be redefined. | |
#define | __VA_TAIL__ __VA_TAIL__ |
A pseudo macro that cannot be redefined. | |
#define | __ZERO__ __EXPAND_DEC__(0) |
A predefined and pre-evaluated 0 | |
#define | ELLIPSIS_LOOP_MAX __EXPAND_DEC__((__ONE__ ◀ (ELLIPSIS_LOOP_WIDTH × ELLIPSIS_LOOP_DEPTH)) - __ONE__) |
The maximum number of iterations of the loop feature. | |
#define | ELLIPSIS_LOOP_WIDTH 4 |
The log₂ of the number of the per-level includes for the loop feature. | |
Predefined macros for all languages.
Provide some convenient short cuts that tend otherwise to be redefined over and over again in user code.
#define ∷ __UNIT__∷ |
#define ∷ __PARENT_UNIT__∷ |
#define __COMPACT__ | ( | X, | |
… | |||
) | __MAP__(__EVALUATE__, X) |
Expand all arguments and remove whitespace surrounding them.
#define __CONCAT__ | ( | … | ) |
evaluate and then concatenate up to 10 arguments
#define __EXPAND__ | ( | … | ) | __VA_ARGS__ |
expand the arguments
#define __EXPAND_BIN__ | ( | … | ) | __EVALUATE_BIN__(__VA_ARGS__) |
expand all the arguments, evaluate the resulting integer expression and produce a binary literal
#define __EXPAND_BIN_U__ | ( | … | ) | __CONCAT__(__EXPAND_BIN__(__VA_ARGS__), U) |
expand all the arguments, evaluate the resulting integer expression and produce a binary literal
The result is a binary integer literal with a U
suffix such that it alwas is interpreted as unsigned number.
#define __EXPAND_COMMAS__ | ( | … | ) | __EXPAND_DEC__(__COMMAS__(__VA_ARGS__)) |
expand all the arguments and count the number of toplevel commas in the resulting list
If there are no arguments, their expansion leads to nothing, or there are any but no toplevel comma, the result is 0
.
#define __EXPAND_DEC__ | ( | … | ) | __EVALUATE_DEC__(__VA_ARGS__) |
expand all the arguments, evaluate the resulting integer expression and produce a decimal literal
The type of the constant is signed if it fits, otherwise unsigned.
#define __EXPAND_DEC_U__ | ( | … | ) | __CONCAT__(__EXPAND_DEC__(__VA_ARGS__), U) |
expand all the arguments, evaluate the resulting integer expression and produce a decimal literal
The result is a decimal integer literal with a U
suffix such that it alwas is interpreted as unsigned number.
expand all the arguments and see if the result is empty
Evaluate the __VA_ARGS__
, use them as an error message and abord compilation.
#define __EXPAND_HEX__ | ( | … | ) | __EVALUATE_HEX__(__VA_ARGS__) |
expand all the arguments, evaluate the resulting integer expression and produce a hexadecimal literal
#define __EXPAND_HEX_U__ | ( | … | ) | __CONCAT__(__EXPAND_HEX__(__VA_ARGS__), U) |
expand all the arguments, evaluate the resulting integer expression and produce a hexadecimal literal
The result is a hexadecimal integer literal with a U
suffix such that it alwas is interpreted as unsigned number.
#define __EXPAND_OCT__ | ( | … | ) | __EVALUATE_OCT__(__VA_ARGS__) |
expand all the arguments, evaluate the resulting integer expression and produce a octal literal
#define __EXPAND_OCT_U__ | ( | … | ) | __CONCAT__(__EXPAND_OCT__(__VA_ARGS__), U) |
expand all the arguments, evaluate the resulting integer expression and produce a octal literal
The result is a octal integer literal with a U
suffix such that it alwas is interpreted as unsigned number.
#define __EXPAND_STRINGIFY__ | ( | … | ) | __STRINGIFY__(__VA_ARGS__) |
expand all the arguments and put the result into one string
#define __MAP__ | ( | F, | |
… | |||
) | __FREEZE__(F)(__VA_ARGS__)__FREEZE__(__VA_OPT__)(, )__FREEZE__(__VA_TAIL__)() |
Construct the body of a macro mapping F
over all variadic arguments.
This can be used in combination with #xdefine to declare a functional macro that maps F
over all its other arguments, as in
If the macro F
receives more than one argument list them all in the call to __MAP__
.
#define __NARGS__ | ( | … | ) | __EXPAND_DEC__(__COMMAS__(__VA_ARGS__) + ¬__EMPTY__(__VA_ARGS__)) |
expand all the arguments and count the number of items in the resulting list
If there are no arguments or their expansion leads to nothing, the result is 0
. Otherwise the result is the number of toplevel commas in the expansion plus one.
#define __ONE__ __EXPAND_DEC__(1) |
A predefined and pre-evaluated 1
#define __PARENT_UNIT__ |
A pseudo-macro that resolves to the name of the current parent unit.
For a top-level C file the parent would be the project name, if that is set from __PROJECT__
, for files that are deeper in the include hierarchy, other subunit names may already have been added to that.
#define __STDC_EMBED_EMPTY__ __EXPAND_DEC__(2) |
A predefined and pre-evaluated value as required by the C standard.
#define __STDC_EMBED_FOUND__ __EXPAND_DEC__(1) |
A predefined and pre-evaluated value as required by the C standard.
#define __STDC_EMBED_NOT_FOUND__ __EXPAND_DEC__(0) |
A predefined and pre-evaluated value as required by the C standard.
#define __STRINGIFY__ | ( | … | ) | ⌗__VA_ARGS__ |
#define __STRINGS__ | ( | X, | |
… | |||
) | __MAP__(__STRINGIFY__, X) |
create a list of strings formed from all the arguments after they are expanded
#define __SUBUNIT__ | ( | NAME | ) |
A pseudo-macro that resolves to a name that is composed with the current parent unit name and NAME
.
For a top-level C file the parent would be the project name, for files that are deeper in the include hierarchy, other subunit names may already have been added to that.
#define __UGLIFY__ | ( | X | ) | __ ⨝ X ⨝ __ |
add two leading and trailing underscores to the identifier X
#define __UNIT__ |
A pseudo-macro that resolves to the name associated with the current translation unit.
This is not set automatically, so if you want to use this feature you'd have to set this manually. Usually this would be done at the start of the translation unit. For a .c
file this would typically look like
for an absolute (unrelated) name or
for a name that is prefixed with the current project name.
In all cases the translation unit may then be abbreviated with .∷
as in
If the name is defined with the __SUBUNIT__
feature, another shortcut ..∷
refers to the parent unit.
Note the use of #xbind (or #expand bind if you prefer): it is important that the whole line is expanded and that the definition is restricted to the current source file.
In a header file, that is generally included into completely unrelated code, you should prefer the first form, such that the contents of the header expands to the same, regardless of the context.
When ellipsis is used as a first phase preprocessor such names are all expanded into long forms that are usually separated by a ‿
character (UNDERTIE, U203F). For example if the project is magn∷ificient
with the above subunit __UNIT__
would expand to magn‿ificient‿macros
and the function name would be magn‿ificient‿macros‿hello
.
#define __UNLIST__ | ( | X, | |
… | |||
) | X __VA_TAIL__() |
Expand all arguments and remove commas between them.
#define __VA_OPT__ __VA_OPT__ |
A pseudo macro that cannot be redefined.
The __VA_OPT__
construct is only active in the replacement list of a variadic macro and must be present at the point of definition. Any other occurence triggers this macro here and passes the token through.
#define __VA_TAIL__ __VA_TAIL__ |
A pseudo macro that cannot be redefined.
The __VA_TAIL__
construct is only active in the replacement list of a variadic macro at the very end of expansion. Any other occurence triggers this macro here and passes the token through.
#define __ZERO__ __EXPAND_DEC__(0) |
A predefined and pre-evaluated 0
#define ELLIPSIS_LOOP_MAX __EXPAND_DEC__((__ONE__ ◀ (ELLIPSIS_LOOP_WIDTH × ELLIPSIS_LOOP_DEPTH)) - __ONE__) |
The maximum number of iterations of the loop feature.
#define ELLIPSIS_LOOP_WIDTH 4 |
The log₂ of the number of the per-level includes for the loop feature.