How to understand such C macro expansion

Posted by upton on Stack Overflow See other posts from Stack Overflow or by upton
Published on 2012-09-08T03:31:55Z Indexed on 2012/09/08 3:37 UTC
Read the original article Hit count: 113

Filed under:
|

A macro definition:

#define HTTP_ERRNO_MAP(XX)                                           \
  /* No error */                                                     \
  XX(OK, "success")                                                  \
                                                                     \
  /* Callback-related errors */                                      \
  XX(CB_message_begin, "the on_message_begin callback failed")       \
  XX(CB_url, "the on_url callback failed")                           \


/* Define HPE_* values for each errno value above */
#define HTTP_ERRNO_GEN(n, s) HPE_##n,
enum http_errno {
  HTTP_ERRNO_MAP(HTTP_ERRNO_GEN)
};
#undef HTTP_ERRNO_GEN

After expand it by "gcc -E",

enum http_errno {
  HPE_OK, HPE_CB_message_begin, HPE_CB_url,};

How does the macro expand to the result?

© Stack Overflow or respective owner

Related posts about c

    Related posts about macros