Welcome to Software Development on Codidact!
Will you help us build our independent community of developers helping developers? We're small and trying to grow. We welcome questions about all aspects of software development, from design to code to QA and more. Got questions? Got answers? Got code you'd like someone to review? Please join us.
Post History
Occasionally I run into some strange pre-processor code with a list like this: #define LIST \ X(1) \ X(2) \ X(3) \ And then code followed by other obscure macros and ...
#1: Initial revision
What are X macros and when to use them?
Occasionally I run into some strange pre-processor code with a list like this: ```c #define LIST \ X(1) \ X(2) \ X(3) \ ``` And then code followed by other obscure macros and macro calls like: ```c typedef enum { #define X(n) ITEM_##n, LIST #undef X } list_t; ``` These are apparently referred to as [X macros](https://en.wikipedia.org/wiki/X_macro). The Wikipedia page is bleak when it comes to describing what these are acutally good for. What are X-macros good for and when should they be used? Which style is preferred? What are the advantages and disadvantages?