[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Variadic macro in definition of fail_msg


On (26/03/15 13:20), Walter Stephan wrote:
>Hi,
>
>since the bug tracker seems to be down, I'll report this here.
>
>The fail_msg macro is defined as follows (in cmocka.h):
>
>#define fail_msg(msg, ...) do { \
>    print_error("ERROR: " msg "\n", ##__VA_ARGS__); \
>    fail(); \
>} while (0)
>
>
>I believe that the '##' token pasting operator is unnecessary, and it causes a warning in my compiler (IAR for ARM):
>
>  Warning[Pe1665]: concatenation with "REDACTED" in macro "fail_msg" does not create a valid token
>
>The following code works fine for me, but I have not tested it on other compilers:
>
>#define fail_msg(msg, ...) do { \
>    print_error("ERROR: " msg "\n", __VA_ARGS__); \
>    fail(); \
>} while (0)
>

I did not test with cmocka but in different project.
Although it works well with varargs.
  fail_msg("a:%d, b%d", a, ,b)

Your approach will fail in case if there are not extra arguments.
  fail_msg("log me")

Tested with gcc and clang (x86_64)

LS


References:
Variadic macro in definition of fail_msgWalter Stephan <stephan.walter@xxxxxxxxxxxxxx>