Alex Rivera | Logout

What does the tilde (~) in macros mean?

Asked 2011-06-25T15:44:41.770
39

Seen on this site, the code shows macro invocations using a tilde in parentheses:

HAS_COMMA(_TRIGGER_PARENTHESIS_ __VA_ARGS__ (~))
//                                          ^^^

What does it mean / do? I suspect it to just be an empty argument, but I'm not sure. Is it maybe specific to C(99) like the __VA_ARGS__ is specific to C99 and existent in C++?

Edit
Report

1 Answer

4

The ~ does nothing. Almost any other content inside those parentheses would work the same.

The lynchpin of this trick is to test whether _TRIGGER_PARENTHESIS_ is next to (~) in the expansion of _TRIGGER_PARENTHESIS_ __VA_ARGS__ (~). Either way, HAS_COMMA(...) expands its arguments to either 0 or 1.

answered 2011-06-25T16:08:23.933

Your Answer