Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Double hash before parameter in function call

I see this line in C:

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

What does the double pound / hash mean before the last param in snprintf()?

like image 479
Phillip Avatar asked Oct 24 '11 18:10

Phillip


2 Answers

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.

like image 184
Thomas Pornin Avatar answered Oct 06 '22 03:10

Thomas Pornin


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

like image 35
Ben Voigt Avatar answered Oct 06 '22 03:10

Ben Voigt