This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Error using variable argument list in a macro

I'm porting a project to the ARM MDK and am running into an error related to a macro with a variable argument list.

I have a macro defined as follows:

#define ADC_PRINTF(format, ...) printf(format, __VA_ARGS__)

(which matches every example I've seen of how to do this)

In the actual usage of the macro, I get the following error from the compiler:

../Core/Src/ADC_control.c(171): error: expected expression
ADC_PRINTF("blah blah blah\n\r");
^
../Core/Inc\ADC_control.h(29): note: expanded from macro 'ADC_PRINTF'
#define ADC_PRINTF(format, ...) printf(format, __VA_ARGS__)
                                                          ^

I'm sure there's something really obvious that I'm missing here.  Any help would be appreciated.

Here are my compiler settings for the project:

Parents
  • C99/C++11 variadic macros don't work if the variadic part of the call is empty.  Anyway, it's frowned upon to use *printf() with just the format string as the argument.  Either make that

    ADC_PRINTF("%s", "blah blah blah\n\r");

    or just puts() / fputs() for simple string outputs that don't really need formatting.

Reply
  • C99/C++11 variadic macros don't work if the variadic part of the call is empty.  Anyway, it's frowned upon to use *printf() with just the format string as the argument.  Either make that

    ADC_PRINTF("%s", "blah blah blah\n\r");

    or just puts() / fputs() for simple string outputs that don't really need formatting.

Children
No data