Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!csd4.milw.wisc.edu!srcsip!tcnet!nis!pwcs!ncs-med!ecd From: ecd@ncs-med.UUCP (Elwood C. Downey) Newsgroups: comp.lang.c Subject: Re: Indefinite-length array as member of struct: how? Summary: "unbounded array" as last member Keywords: char string [] [0] [1] Message-ID: <1075@ncs-med.UUCP> Date: 19 Jul 89 18:31:57 GMT References: <7360@c3pe.UUCP> <821@fozzy.UUCP> <14465@dartvax.Dartmouth.EDU> Organization: Dimensional Medicine, Inc. Minnetonka, MN. Lines: 17 You might make an array member of length 1 at the end of a struct, then malloc enough room for all that you really need and index into it via the array. for example: struct s { ... /* anything ... */ char array[1]; /* must be last member */ }; f(n) int n; { struct s *sp; sp = malloc (sizeof(struct s) + n - 1); /* you get 1 already */ /* now you can use sp->array[0..n-1] */ }