4 ms·
The most interesting things about C preprocessor is compile-time zero-overhead tuples and variadic macro overloading. e.g you can pass (a,b,c) as single argumen
by FrozenVoid 9y ago
The most interesting things about C preprocessor is compile-time zero-overhead tuples and variadic macro overloading.
e.g you can pass (a,b,c) as single argument to function(a) macros and selectively alter the tuple members and perform clever tricks which look like lisp code blocks unrolled at compile time(visible with gcc -E).
Boost preprocessor and Order use it to create very powerful abstractions. see http://www.boost.org/doc/libs/1_64_0/libs/preprocessor/doc/index.html http://www.boost.org/doc/libs/1_64_0/libs/preprocessor/doc/i... https://github.com/rofl0r/order-pp https://github.com/rofl0r/order-pp
Variadic overloading of function macros is technique from http://stackoverflow.com/questions/11761703/overloading-macro-on-number-of-arguments http://stackoverflow.com/questions/11761703/overloading-macr... combined with _Generic which overloads by type. It allows things like print("abc",1.2,3) to transform into printf("%s","abc"),printf("%f",1.2),printf("%d",3)
without any overhead in the generated code.
see https://www.reddit.com/r/frozenvoid/wiki/voidh https://www.reddit.com/r/frozenvoid/wiki/voidh
Edit: and the tuple members are just symbolic tokens, they can contain anything from code to nested tuple trees.
(code can be encapsulated in https://gcc.gnu.org/onlinedocs/gcc/Statement-Exprs.html https://gcc.gnu.org/onlinedocs/gcc/Statement-Exprs.html)