-4

Recently i am working IEC std code

I found a similar question here but it is not the same as this exactly. macro with (...).

Here is a piece of code about this:

#define DPRINTF(...)

DPRINTF("token end: %p\n", end);

What does the macro "#define DPRINTF(...)" mean?

jww
  • 97,681
  • 90
  • 411
  • 885
Maari R
  • 9
  • 5
  • 1
    It's a *variadic macro*. – Bathsheba Mar 19 '19 at 12:31
  • 1
    Read [this](https://stackoverflow.com/questions/39669257/how-to-use-dprintf) and [this](https://gcc.gnu.org/onlinedocs/cpp/Variadic-Macros.html) and [this](https://en.cppreference.com/w/cpp/preprocessor) – NathanOliver Mar 19 '19 at 12:33
  • 2
    What's with the random letters? Why should be leave it? And if you found a similar question, why not link to it directly? Please refresh [the help pages](http://stackoverflow.com/help), re-take [the SO tour](http://stackoverflow.com/tour), and re-read about [how to ask good questions](http://stackoverflow.com/help/how-to-ask) as well as [this question checklist](https://codeblog.jonskeet.uk/2012/11/24/stack-overflow-question-checklist/). And don't forget to put your question in the actual question (and keep the title a show summary of your problem/question). – Some programmer dude Mar 19 '19 at 12:37
  • 1
    Possible duplicate of [A #define in C with three dots](https://stackoverflow.com/q/12434626/608639), [How to make a variadic macro (variable number of arguments)](https://stackoverflow.com/q/679979/608639), etc. – jww Mar 19 '19 at 12:46

1 Answers1

1

This is called a variadic macro It allows you to pass an arbitrary number of arguments to this macro and there are means to iterate over all of these.

As @user463035818 mentioned, your definition does not do anything. Hence, the call to it will simply be removed by the preprocessor.

Edit about the usage: What you want to do here is likely a printf-like macro for debug output. In this case you might want to write something like this:

#define DPRINTF(msg, ...) \
  printf("[DEBUG at %s:%s]: %s", __FILE__, __LINE__, msg, __VA_ARGS__);

Note this is not tested. This should print lines starting with the prefix noting "DEBUG" and the file and line it is called in, in combination with the user passed format literal and all arguments you want, e.g.:

// log something out
DPRINTF("Hello %s\n", "World")
Thomas Lang
  • 770
  • 1
  • 7
  • 17