3 ms·
What is this sorcery? #include <datatype99.h> datatype( BinaryTree, (Leaf, int), (Node, struct BinaryTree *, i
by enriquto 6y ago
What is this sorcery?
#include <datatype99.h>
datatype(
BinaryTree,
(Leaf, int),
(Node, struct BinaryTree *, int, struct BinaryTree *)
);
What kind of preprocessor black magic can you do so that this code compiles? I don't dare to open the file datatype99.h lest it casts a dark spell on me.
- willxinc 6y agohttps://github.com/Hirrolot/epilepsy https://github.com/Hirrolot/epilepsy According to the GitHub, which appears to be a metaprogramming library by the same author.
- flohofwoe 6y agoThe whole system seems to be built on top of variadic macros (which had been standardized in C99).
- Hirrolot 6y agoYes, as others have already noticed, it is implemented on top of https://github.com/Hirrolot/epilepsy https://github.com/Hirrolot/epilepsy, a metalanguage for preprocessor metaprogramming.
- jrimbault 6y ago> a metalanguage for preprocessor metaprogramming That sentence is everything I was taught to avoid. Props to you. I like the drug/alcohol metaphor for these things, as a child avoid them, as an adult do your thing as long as you remain sensible.
- globuous 6y agoFunny you use this example, the author's GH page says he's 16; in many countries he wouldn't be able to drink, event responsibly ^^
- masklinn 6y ago> in many countries he wouldn't be able to drink But in most countries they would be able to drink (especially in a private setting), just not purchase. In Europe for instance less than half a dozen countries have a minimum drinking age for private settings, and a dozen more have an MDA in public (but not private), though for some 16 is enough to drink fermented alcohols (alongside a meal with adults for the UK, regardless for Germany and Austria).
- enriquto 6y agoLOL, I cannot get enough of this shit! Can you point to some cool implementation tricks that you used to achieve that? I guess there's quite a bit of ## concatenation to create temporary names and stuff?
- Hirrolot 6y agoWell, mostly I use idioms from the Cloak Wiki (https://github.com/pfultz2/Cloak/wiki/C-Preprocessor-tricks,-tips,-and-idioms https://github.com/pfultz2/Cloak/wiki/C-Preprocessor-tricks,...). It takes some time to realise them :)
- orra 6y agoIn case anybody mistakenly thinks doing so is 'cheating', you're the author of both libraries! This is absurd, but in a good way.