GCC: does array type have an incomplete element type?

GCC gives me a message like "array type with incomplete element type" when I try to compile this:

typedef struct _node node;
struct _node{
 int foo;
 node (*children)[2];
 int bar;
};

In memory, the structure should look like this:

0x345345000000 foo
0x345345000004 pointer to 1. child node
0x345345000008 pointer to 2. child node
0x34534500000C bar
+1
source share
2 answers

This is because an expression of type C works the other way around.

It:

node (*children)[2];

reads as follows: the contents children, when dereferencing ( *applies to them), enter something that the array operator can apply to [], giving node. This means that it childrenis a pointer to an array of two node. However, you do not need a pointer to an array, you need an array of two pointers. To do this, you must put parentheses this way:

node *(children[2]);

: children ; * , a node. , : node. , :

node *children[2];

C, , [] *.

C , , , , node ( ), , , type " node". .

: _node , . "". , . , : typedef struct node_ node;

+7

:

 node (*children)[2];

:

 struct _node* children[2];
+2

All Articles