Mail Archives: djgpp/1999/03/11/20:29:05
Holger Wahlen wrote:
>
> rpolzer AT gmx DOT de asked:
>
> > Can I do the following: (in C++)
> >
> > struct PACKET {
> > // ... some data
> > char P_DATA[0];
> ^^^
> > };
>
> Typo, I guess.
Not necessarily. It's a GCC extension to support a hack that's seen
occasionally to implement variable-length structures. For instance:
struct message {
int length;
char body[0];
};
void pass_message(char *s)
{
struct message *p;
p = malloc (sizeof(struct message) + strlen(s) + 1 /* null */ );
strcpy(p->body, s);
p->length = strlen(s);
transmit(p);
}
In traditional implementations you would have to use `char body[1]',
which is a bit more awkward.
--
Nate Eldredge
nate AT cartsys DOT com
- Raw text -