Double hash before parameter in function call

前端 未结 3 1758
我在风中等你
我在风中等你 2020-12-09 11:35

I see this line in C:

#define log(format, args...) snprintf(buffer + strlen(buffer), 1023 - strlen(buffer), format, ##args);

What does the

相关标签:
3条回答
  • 2020-12-09 12:15

    That's the "token-pasting" preprocessor operator, and I don't think that macro uses it correctly.

    0 讨论(0)
  • 2020-12-09 12:16

    In standard C, the "##" is for concatenating tokens together within a macro. Here, this macro is not in standard C, but in "Gnu C", the dialect implemented by GCC. The "##" is used to remove the comma if the extra arguments (in args) turn out to be empty. See the GCC manual.

    0 讨论(0)
  • 2020-12-09 12:25

    This is a gcc extension (so is args..., the C99 version is to use ... and __VA_ARGS__) to remove the final comma if the variable argument list args is empty.

    0 讨论(0)
提交回复
热议问题