Struct initialisation through macro overuse <p>I've got some structs to initialise, which would be tedious to do manually. I'd like to create a macro that will help me with it... but I'm not sure the <strong>C</strong> preprocessor is good enough for this.</p> <p>I've got structs which represent menus. They consist of function pointers only:</p> <pre><code>typedef uint8_t (*button_handler) (uint8_t); typedef void (*pedal_handler) (void); typedef void (*display_handler) (void); typedef void (*menu_switch_handler) (void); #define ON_BUTTON(x) uint8_t menu_frame_##x##_button (uint8_t button) #define ON_PEDAL(x) void menu_frame_##x##_pedal (void) #define ON_DISPLAY(x) void menu_frame_##x##_display (void) #define ON_SWITCH(x) void menu_frame_##x##_switch (void) typedef struct menu_frame { button_handler on_button; pedal_handler on_pedal; display_handler on_display; menu_switch_handler on_switch; } menu_frame; </code></pre> <p>That allows me to write the functions and separate functions as (.c file):</p> <pre><code>ON_BUTTON(blah) { ... } </code></pre> <p>and menus as (.h file):</p> <pre><code>ON_BUTTON(blah); ON_DISPLAY(blah); menu_frame menu_frame_blah = { menu_frame_blah_button, NULL, menu_frame_blah_display, NULL }; </code></pre> <p>Is there any way I can fold the menu definition into one define? I could do something that expands <code>MENU(blah, menu_frame_blah_button, NULL, menu_frame_blah_display, NULL)</code> of course, but is there any way to:</p> <ul> <li>make it shorter (NULL or some name)</li> <li>remove the need of <code>ON_BUTTON(...);</code> from before the struct</li> </ul> <p>Ideally, I'd like <code>MENU(blah, button, NULL, display, NULL)</code> to both define the handlers and the menu struct itself. I don't know for example how to prevent expanding the last term into <code>ON_SWITCH(NULL)</code>.</p> <p>Or maybe I should approach it from some other way?</p>