Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!samsung!umich!ox.com!math.fu-berlin.de!fauern!unido!rwthinf!marvin.e17.physik.tu-muenchen.de!berg From: berg@marvin.e17.physik.tu-muenchen.de (Stephen R. van den Berg) Newsgroups: comp.lang.c Subject: Variable structure size -- ANSI ? Message-ID: <4204@rwthinf.UUCP> Date: 11 Apr 91 10:48:27 GMT References: <8334@umd5.umd.edu> <3111@kluge.fiu.edu> Sender: news@rwthinf.UUCP Lines: 23 Michael N Johnston writes: ]>struct foo { ]>unsigned short recsize; ]>unsigned short num; ]>char info [24]; ]>byte flags; ]>char filename[1] ]>}; ]>Where, foo.filename is a placeholder for a variable length string. ]If you plan to store a char array in filename DON'T. Use char *filename ]and point this to your actual array. Using your origional declaration ]and doing something like strcpy(foo_ptr->filename, "abcde") will lead ]to disaster. Why should this lead to disaster? Is this not allowed by ANSI? If you can make sure that you have malloced more than enough space for the structure, shouldn't you be able to use all this space by doing just that? -- Sincerely, berg@marvin.e17.physik.tu-muenchen.de Stephen R. van den Berg. "I code it in 5 min, optimize it in 90 min, because it's so well optimized: it runs in only 5 min. Actually, most of the time I optimize programs."