Path: utzoo!attcan!uunet!mcvax!kth!draken!tut!router!vtt!savela From: savela@tel2.tel.vtt.fi (Markku Savela) Newsgroups: comp.lang.c Subject: Re: Indefinite-length array as member of struct: how? Summary: Not the answer, but offsetof helps some... Keywords: offsetof Message-ID: <2607@tel2.tel.vtt.fi> Date: 8 Jul 89 21:29:08 GMT References: <7360@c3pe.UUCP> <8870@venera.isi.edu> Reply-To: savela%vtttel@router.funet.fi Organization: Technical Research Centre of Finland Lines: 19 In article <8870@venera.isi.edu>, lmiller@venera.isi.edu (Larry Miller) writes: > In article <7360@c3pe.UUCP> charles@c3pe.UUCP (Charles Green) writes: >>struct node { >> struct node* next; >> char string[]; >>} *nodeptr; > > nodeptr = malloc(strlen(data)+1 + sizeof(struct node *)); This the prime example where the ANSI "offsetof"-macro becomes handy. I write the above (struct node *)malloc(offsetof(struct node,string)+strlen(data)+1); About the original question, I guess we have to resign to using either "string[1]" or "string[HUGE_NUMER]" to satisfy picky compilers. (Isn't this one of the recurring questions of comp.lang.c?) -- Markku Savela