Why use char placeholder[0] ?

Hi all:
I read a book on linux networking internals,which declares a data structure below:
1
2
3
4
5
6
7
struct abc
{
 int age;
 char* name[20];
 ...
 char placeholder[0];
};  


So,i dont understand what is the char array of placeholder(zero size) for ? At first glance, i am really frustrated by code like this.

Any help is well appreciated.
I've never used them but found this:

http://gcc.gnu.org/onlinedocs/gcc/Zero-Length.html

What I figure is that it's essentially a pointer to the byte after the structure. So if you were making an IP header for example you would define the IP stuff in the structure and have a placeholder for the following TCP header...
thanks for the link.
currently i am a little dizzy,could not understand what the link trying to convey ? I might read them again in the next morning or some other time.
Typically it is a C way of saying that an arbitrary number of bytes follow.

A contrived example:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
struct packet {
    int from;
    int to;
    int data_len;
    char data[0];   // length of data is known at runtime, not compile time
};

void send_data( char buf[], int len, int from, int to ) {
    struct packet* pkt = (struct packet*)malloc( sizeof( struct packet ) + len ); // allocate space for packet AND data
    pkt->from = from;
    pkt->to = to;
    pkt->data_len = len;
    memcpy( pkt->data, buf, len );
    // ...
}


However, to be portable, you should not use zero-length arrays.
Topic archived. No new replies allowed.