Nested dynamic structure in C?

Is it possible to have two arrays with flexible size inside the same structure?

I know I can do something like below

struct A {
    int countB;
    struct B[0];
}

But my question is: can we do something like below?

struct A {
    int countB;
    struct B[0];
    int countC;
    struct C[0];
}

If so, how do we get the offset countC?

If the foregoing is very difficult to implement, is it possible to easily cope with such situations?

+4
source share
1 answer

No, you are not allowed to use more than one flexible size array for each data structure:

6.7.2.1.16: As a special case, the last structure element with more than one named element may have an incomplete array type; this is called a flexible array element.

, , , ( struct) , .

, , C B:

struct A {
    int countB;
    int countC;
    struct some_struct *C;
    struct some_struct B[0];
};

struct A, countB+countC. C B+countB.

+3

Source: https://habr.com/ru/post/1628586/


All Articles