0

There is not much information about this. Is this the one and only way to do comment in C macro definition? Or can I make add comment using another way?

#define TEST(a, b) \
{ \
    bool aGb = false;\
    bool bGc = false;\
    /* comment is here */ \
    if (a > b) \
    {\
        ... \
    }\
}
alk
  • 69,737
  • 10
  • 105
  • 255
DRINK
  • 452
  • 1
  • 6
  • 15

2 Answers2

2

You can do this:

#define DOC(ignored)

And combine like so:

#define TEST(a, b) \
{ \
    bool aGb = false; \
    bool bGc = false; \
    DOC((This is a comment, hello world!)) \
    if (a > b) \
    { \
        ... \
    } \
}

Naturally you can't use the C99 comment style with //, since it would ignore the rest of the line and prevent you from creating a multi-line macro.

I would personally suggest just getting used to /* comment */ style. For a start, people using syntax-highlighting IDEs with your code won't see the highlighting if you use this DOC macro above.

1

The only limitation which adds to those already present when commenting "real" C sources is, that you may not add anything on a macro's "source" line after the final backslash.

alk
  • 69,737
  • 10
  • 105
  • 255