4 ms·
Sending blocks as arguments to macros: Just wrap them in another set of parentheses. For parentheses-balanced input (such as valid C blocks) this should always
by jstimpfle 9y ago
Sending blocks as arguments to macros: Just wrap them in another set of parentheses. For parentheses-balanced input (such as valid C blocks) this should always work (I think).
$ echo '#define x(a,b,c) a b
x(1, (2, 3), 5)' | cpp
- mort96 9y agoThat isn't really a viable solution, because C doesn't allow parentheses around blocks. Calling `describe(foo, ({ int a, b; }))` would make the preprocessor happy, but it would also produce invalid syntax: void test_foo() ({ int a, b; })
- cryptonector 9y agoTsk tsk, if you're going to know about label values and other GCC C extensions, you might as well know about statement expressions (another GCC C extension). `({ <statements> })` is an expression. Naturally, Clang also supports statement expressions... EDIT: I highly recommend spending some time reading about all the various GCC C extensions, and what compilers support them (typically Clang, but also Sun Studio, if that's still around..., and maybe others). There are quite a few very useful ones.