I have these two structures…
typedef struct{
MY_SECOND_STRUCT s1;
}MY_FIRST_STRUCT;
typedef struct{
int s1;
}MY_SECOND_STRUCT;
I prefer this order, I dont want to switch them.
But compiler dont know MY_SECOND_STRUCT at the moment and I get error
error: expected specifier-qualifier-list before ‘MY_SECOND_STRUCT’
I´ve tried add declaration to the top
struct MY_SECOND_STRUCT;
also change definition to
typedef struct{
struct MY_SECOND_STRUCT s1;
}MY_FIRST_STRUCT;
but it didnt help.
That order is not possible. You have to switch them.
However, if you declare the member as pointer, then switching is not required:
Or, in C++ you can use template as:
And when you want to use
MY_FIRST_STRUCT, just use thistypedef:Use
MY_FIRST_STRUCTnow. 🙂