2

First, it declares the macro LOG_DBG(x) just like this:

#define LOG_DBG(x)

And then, use it like this:

LOG_DBG((LOG_MISC, 80, __FUNCTION__": select reports %d", res));

And I can't understand what the macro means ? What it will do ?

karllo
  • 341
  • 3
  • 10

3 Answers3

4

It does exactly nothing. It gets preprocessed to an empty string. This may be a somewhat convenient way of disabling/enabling debug log messages. The code was probably written like this at some point:

#define LOG_DBG(x) some_logging_function(x)

But then someone wanted to simply get rid of all the log messages in one shot.

dragosht
  • 3,237
  • 2
  • 23
  • 32
1

It will do nothing. You're seeing the "disabled" form of the macro, which is used to make the logging calls go away on non-debug builds.

There should be another declaration of the macro somewhere, or the code is perhaps just "left" in the non-debugging state.

unwind
  • 391,730
  • 64
  • 469
  • 606
1

You've defined a macro that receives x as parameter but do nothing. Here's a concrete use of macro:

#include <stdio.h>

#define LOG_DBG(x) ((x)+5)
int main(int argc, char *argv[])
{
  int x = LOG_DBG(3);
  printf("%d\n", x);
  return 0;
} 

Here, we did something in the macro and hence the number 8 will be printed.

Of course, if you want the logarithm of x, it would be another expression.

Mickey
  • 480
  • 4
  • 13
  • 1
    That's a really bad example, it's not very likely that this macro is really about computing the logarithm, rather it's about logging for debug purposes. Also, your macro definition (`x+5`) fails to bracket the argument in parentheses, which is good practice. – unwind Jul 09 '14 at 08:12
  • I've edited the parentheses (although it will work at this simple example). What I wanted to show, is how to use a macro and demonstrate it with an example. – Mickey Jul 09 '14 at 08:41
  • No, that's not what I meant with the parentheses. Please see e.g. [this answer](http://stackoverflow.com/questions/10820340/the-need-for-parentheses-in-macros-in-c) for a discussion. – unwind Jul 09 '14 at 08:47
  • Oops, I forgot it. my mistake. Thank you for notice me, the answer was edited. – Mickey Jul 09 '14 at 13:08