APPLY_MACRO_FOREACH
- Macro
- August 22, 2025
Table of Contents
APPLY_MACRO_FOREACH
APPLY_MACRO_FOREACH
Description
Expand variadic argument list for given macro for each element one by one. This is a macro trick to apply a given macro on a variadic argument list one by one. The only limitiation here is that we cannot expand more than 256 times for the moment. To make it do more than that, we just need to add one more line to the EXPAND macros Also, if you have more than 20-30 arguments in your format strings, you should seriously consider whether you’re doing something wrong Reference : https://www.scs.stanford.edu/~dm/blog/va-opt.html
Usage example (Cross-references)
- In
Io.h:286
:
fmtstr, \
((TypeSpecificIO[]) { \
APPLY_MACRO_FOREACH(IOFMT_LVAL_APPEND_COMMA, __VA_ARGS__) {NULL, NULL, NULL} \
}) \
)
- In
Io.h:318
:
fmtstr, \
((TypeSpecificIO[]) { \
APPLY_MACRO_FOREACH(IOFMT_APPEND_COMMA, __VA_ARGS__) {NULL, NULL, NULL} \
}) \
)
- In
Io.h:351
:
fmtstr, \
((TypeSpecificIO[]) { \
APPLY_MACRO_FOREACH(IOFMT_APPEND_COMMA, __VA_ARGS__) {NULL, NULL, NULL} \
}) \
)
- In
Io.h:384
:
fmtstr, \
((TypeSpecificIO[]) { \
APPLY_MACRO_FOREACH(IOFMT_LVAL_APPEND_COMMA, __VA_ARGS__) {NULL, NULL, NULL} \
}) \
)
- In
Io.h:421
:
fmtstr, \
((TypeSpecificIO[]) { \
APPLY_MACRO_FOREACH(IOFMT_LVAL_APPEND_COMMA, __VA_ARGS__) {NULL, NULL, NULL} \
}) \
)