You are making hard work of it, you have a C11 compiler :-) Unionize the struct pointers .. they are all pointers to different types
typedef union {
void* void_ptr;
struct mySmallStruct1_s* SmallStruct1_ptr;
struct mySmallStruct2_s* SmallStruct2_ptr;
struct mySmallStruct3_s* SmallStruct3_ptr;
} smallstruct_ptr;
struct mySmallStruct1_s {
smallstruct_ptr ptrToNextElement;
int myArray[1];
};
struct mySmallStruct2_s {
smallstruct_ptr ptrToNextElement;
int myArray[2];
};
struct mySmallStruct3_s {
smallstruct_ptr ptrToNextElement;
int myArray[3];
};
struct myBigStruct_s {
struct mySmallStruct1_s mySmallStruct1;
struct mySmallStruct2_s mySmallStruct2;
struct mySmallStruct3_s mySmallStruct3;
};
struct myBigStruct_s myBigStruct = {
{ .ptrToNextElement.SmallStruct2_ptr = &myBigStruct.mySmallStruct2, .myArray[0] = 0 },
{ .ptrToNextElement.SmallStruct3_ptr = &myBigStruct.mySmallStruct3, .myArray[0] = 0, .myArray[1] = 0 },
{ .ptrToNextElement.void_ptr = 0,.myArray[0] = 0,.myArray[1] = 0, .myArray[2] = 0 }
};
struct myBigStruct_s myBigStruct1 = {
{ .ptrToNextElement.SmallStruct2_ptr = &myBigStruct1.mySmallStruct2,.myArray[0] = 1 },
{ .ptrToNextElement.SmallStruct3_ptr = &myBigStruct1.mySmallStruct3,.myArray[0] = 1,.myArray[1] = 2 },
{ .ptrToNextElement.void_ptr = 0, .myArray[0] = 1,.myArray[1] = 2,.myArray[2] = 3 }
};
In vino veritas