Skip to content

Commit

Permalink
app: use portable variadic macros
Browse files Browse the repository at this point in the history
Many places are using a GCC extension related to variadic macros,
where a name prepends the ellipsis. This results in a warning like
the one below when compiling the code with MSVC:

app\test-pmd\testpmd.h(1314): error C2608:
    invalid token '...' in macro parameter list

Variadic macros became a standard part of the C language with C99.
GCC, Clang and MSVC handle them properly.

The fix is to remove the prefix name (args... becomes ...) and use
__VA_ARGS__.

Signed-off-by: Andre Muezerie <[email protected]>
  • Loading branch information
Andre Muezerie authored and david-marchand committed Dec 23, 2024
1 parent ba9fb27 commit f7c9651
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 13 deletions.
4 changes: 2 additions & 2 deletions app/test-acl/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -423,9 +423,9 @@ static const char cb_port_delim[] = ":";

static char line[LINE_MAX];

#define dump_verbose(lvl, fh, fmt, args...) do { \
#define dump_verbose(lvl, fh, fmt, ...) do { \
if ((lvl) <= (int32_t)config.verbose) \
fprintf(fh, fmt, ##args); \
fprintf(fh, fmt, ##__VA_ARGS__); \
} while (0)


Expand Down
12 changes: 6 additions & 6 deletions app/test-eventdev/evt_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,16 @@
#define CLGRN "\x1b[32m"
#define CLYEL "\x1b[33m"

#define evt_err(fmt, args...) \
fprintf(stderr, CLRED"error: %s() "fmt CLNRM "\n", __func__, ## args)
#define evt_err(fmt, ...) \
fprintf(stderr, CLRED"error: %s() "fmt CLNRM "\n", __func__, ## __VA_ARGS__)

#define evt_info(fmt, args...) \
fprintf(stdout, CLYEL""fmt CLNRM "\n", ## args)
#define evt_info(fmt, ...) \
fprintf(stdout, CLYEL""fmt CLNRM "\n", ## __VA_ARGS__)

#define EVT_STR_FMT 20

#define evt_dump(str, fmt, val...) \
printf("\t%-*s : "fmt"\n", EVT_STR_FMT, str, ## val)
#define evt_dump(str, fmt, ...) \
printf("\t%-*s : "fmt"\n", EVT_STR_FMT, str, ## __VA_ARGS__)

#define evt_dump_begin(str) printf("\t%-*s : {", EVT_STR_FMT, str)

Expand Down
7 changes: 4 additions & 3 deletions app/test-mldev/ml_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@

#define ML_STR_FMT 20

#define ml_err(fmt, args...) fprintf(stderr, CLRED "error: %s() " fmt CLNRM "\n", __func__, ##args)
#define ml_err(fmt, ...) \
fprintf(stderr, CLRED "error: %s() " fmt CLNRM "\n", __func__, ##__VA_ARGS__)

#define ml_info(fmt, args...) fprintf(stdout, CLYEL "" fmt CLNRM "\n", ##args)
#define ml_info(fmt, ...) fprintf(stdout, CLYEL "" fmt CLNRM "\n", ##__VA_ARGS__)

#define ml_dump(str, fmt, val...) printf("\t%-*s : " fmt "\n", ML_STR_FMT, str, ##val)
#define ml_dump(str, fmt, ...) printf("\t%-*s : " fmt "\n", ML_STR_FMT, str, ##__VA_ARGS__)

#define ml_dump_begin(str) printf("\t%-*s :\n\t{\n", ML_STR_FMT, str)

Expand Down
4 changes: 2 additions & 2 deletions app/test-pmd/testpmd.h
Original file line number Diff line number Diff line change
Expand Up @@ -1311,7 +1311,7 @@ RTE_INIT(__##c) \
#endif
#endif /* __GCC__ */

#define TESTPMD_LOG(level, fmt, args...) \
rte_log(RTE_LOG_ ## level, testpmd_logtype, "testpmd: " fmt, ## args)
#define TESTPMD_LOG(level, fmt, ...) \
rte_log(RTE_LOG_ ## level, testpmd_logtype, "testpmd: " fmt, ## __VA_ARGS__)

#endif /* _TESTPMD_H_ */

0 comments on commit f7c9651

Please sign in to comment.