4 ms·
C's preprocessor not being powerful enough is less a problem with text-substitution macros, more that they're not allowed to expand recursively which was an int
by johnnyjeans 1y ago
C's preprocessor not being powerful enough is less a problem with text-substitution macros, more that they're not allowed to expand recursively which was an intentional design choice. There are some hacks you can do to get around it, and people have done cool things[1] within the limited space those hacks grant you, but there's a reason many C projects with extensive metaprogramming just use an external macro language (which is also just text-substitution).
IMO AST Macros are an even bigger problem than text substitution. Debugging metaprogramming of any kind past a certain point of complexity is a royal pain in the ass (even in a Lisp, Forth or Prolog), but AST explorers are next to useless for complicated logic problems that involve needle in a haystack searches of side effects. If you're dealing with a large AoS of heterogeneous SoAs which influence each other to shuffle around, and most of the related code and the structures themselves are generated via AST macros, you better be really comfortable with assembly analysis and debugger scripting.
[1] - https://github.com/Hirrolot/datatype99 https://github.com/Hirrolot/datatype99
- kazinator 1y agoDebugging complex Lisp metaprogramming is a piece of cake in the overall debugging landscape. - It is not distributed across machines. No distributed fault tolerance issues. - It doesn't run on a resource constrained embedded system, with poor visibility, but in your dev environment. - It runs in a single thread; no flaky race conditions or deadlocks to debug. - Its expansion-time performance rarely matters; and it is rarely bogged down with machine dependencies or other low-level stuff. - It is unit-testable with cases does construct X expanding to construct Y. I would rather debug a macro than any number of other things I've also debugged.