Re:No Us Without You: elifdef and elifndef
by foundry27 on Monday March 15, 2021 @01:07PM
(#26468560)
Looping is already totally doable, up to a finite maximum number of iterations. Local variables and the like can be simulated through suitably clever preprocessor definitions and logic, too. The syntax and trickery you need to take advantage of it is thoroughly, thoroughly unpleasant though.
For anyone curious about the practicality of that sort of thing, A CPS macro continuation machine like https://github.com/rofl0r/order-pp/blob/master/inc/order/cm.... would give you about 18 quintillion loop iterations if my math was right; double the length of that file and you’d have more loop iterations than atoms in the universe.
That said, there is so much C code in existence assuming the existing C preprocessor, it is more feasible to add new features to the existing one than replace it with something new and incompatible.
I wish they'd add some better syntax for multi-line macros. So instead of:
you could write something like this: Get rid of the backslashes (which are easy to screw up). It would also enable you to use #if conditionals inside the #macro block, so you could easily write conditional macros.Also, maybe instead of the do { ... } while (0) trick, #macro could automatically insert do { } while (0), maybe say if the #macro had a { on the same line:
Some kind of looping support (e.g. #while) would also be great: In the above, #local is #define but local to the #macro block.