Standard states C (Β§6.2.5, p22):
An unknown array size type is incomplete. It is completed, for an identifier of this type, indicating the size in a later version of the declaration (with internal or external communication).
And it works great with respect to variable declarations:
int a[]; int a[2];
But when we add a typedef in front of these declarations, the compiler complains (I also changed the name):
typedef int t[]; typedef int t[2];
He does not complain, however, when we complete the typedef for an incomplete structure:
typedef struct t t1; typedef struct t { int m; } t1;
A possible use case for an incomplete typedef array might be something like this:
int main(int n, char **pp) { typedef int t1[][200]; typedef struct t { t1 *m; int m1; } t0; typedef int t1[sizeof (t0)][200]; }
In the above example, I would like to declare a pointer to an array inside the structure with the number of elements equal to the size of the structure. Yes, I could use a structure instead of an array, but why should I use a potentially available option?
c arrays language-lawyer
AnArrayOfFunctions
source share