Zero Length Arrays Allowed in C Standard?

Bjorn Engsig bengsig at oracle.nl
Thu Dec 7 20:32:23 AEST 1989


Article <11751 at smoke.BRL.MIL> by gwyn at brl.arpa (Doug Gwyn) says:
|I use the [1] kludge on occasion, but I raise flags when I do because
|it is not guaranteed to work.
Would you please explain why, and also tell what is the portable way of
having a 'variable length "thing"' in C.

Article <4733 at solo11.cs.vu.nl> by maart at cs.vu.nl (Maarten Litmaath) proposed:
|	typedef struct SYMTAB {
|		struct SYMTAB *sym_next;
|		int     sym_type;
|		char    *sym_text;
|	} SYMTAB;
|
|symtabptr = (SYMTAB *) malloc(sizeof(SYMTAB) + strlen(text) + 1);
|symtabptr->sym_text = (char *) symtabptr + sizeof(SYMTAB);
|strcpy(symtabptr->sym_text, text);
Is that portable, or do you have to use two mallocs (one for the struct,
and one for the string)?
-- 
Bjorn Engsig,	Domain:		bengsig at oracle.nl, bengsig at oracle.com
		Path:		uunet!{mcsun!orcenl!bengsig,oracle!bengsig}



More information about the Comp.lang.c mailing list