APPLY_MACRO_FOREACH

Table of Contents

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)

    fmtstr,                                                                                                        \
    ((TypeSpecificIO[]) {                                                                                          \
    APPLY_MACRO_FOREACH(IOFMT_LVAL_APPEND_COMMA, __VA_ARGS__) {NULL, NULL, NULL}                               \
    })                                                                                                             \
    )
    fmtstr,                                                                                                        \
    ((TypeSpecificIO[]) {                                                                                          \
    APPLY_MACRO_FOREACH(IOFMT_APPEND_COMMA, __VA_ARGS__) {NULL, NULL, NULL}                                    \
    })                                                                                                             \
    )
    fmtstr,                                                                                                        \
    ((TypeSpecificIO[]) {                                                                                          \
    APPLY_MACRO_FOREACH(IOFMT_APPEND_COMMA, __VA_ARGS__) {NULL, NULL, NULL}                                    \
    })                                                                                                             \
    )
    fmtstr,                                                                                                        \
    ((TypeSpecificIO[]) {                                                                                          \
    APPLY_MACRO_FOREACH(IOFMT_LVAL_APPEND_COMMA, __VA_ARGS__) {NULL, NULL, NULL}                               \
    })                                                                                                             \
    )
    fmtstr,                                                                                                        \
    ((TypeSpecificIO[]) {                                                                                          \
    APPLY_MACRO_FOREACH(IOFMT_LVAL_APPEND_COMMA, __VA_ARGS__) {NULL, NULL, NULL}                               \
    })                                                                                                             \
    )

Share :