// Simple message structures typedef struct { int a; } MsgA; typedef struct { int b; } MsgB; typedef struct { int c; } MsgC; typedef struct { int d; } MsgD; typedef struct { int e; } MsgE; typedef struct { int f; } MsgF; // X-Macro for list elements: X(name,MsgName) #define MY_LIST1 \ X(aaa, MsgA)\ X(bbb, MsgB)\ X(ccc, MsgC)\ // X-Macro for list elements: X(name,MsgName) #define MY_LIST2 \ X(ddd, MsgD)\ X(eee, MsgE)\ X(fff, MsgF)\ // Generate structure of all messages #define X(name,MsgName) MsgName name; static struct { MY_LIST1 MY_LIST2 } list1_ = {0}; #undef X // Generate structure of all messages #define X(name,MsgName) struct { MsgName msg; } name; static struct { MY_LIST1 MY_LIST2 } list2_ = {0}; #undef X // Generate structure of all messages #define X(name,MsgName) struct { MsgName msg; } list3_##name; MY_LIST1 MY_LIST2 #undef X static void test() { list1_.aaa.a; list1_.ddd.d; list1_.bbb.b; list1_.eee.e; list1_.ccc.c; list1_.fff.f; list2_.aaa.msg.a; list2_.ddd.msg.d; list2_.bbb.msg.b; list2_.eee.msg.e; list2_.ccc.msg.c; list2_.fff.msg.f; list3_aaa.msg.a; list3_ddd.msg.d; list3_bbb.msg.b; list3_eee.msg.e; list3_ccc.msg.c; list3_fff.msg.f; }