Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!utgpu!water!watnot!watmath!clyde!cuae2!gatech!lll-lcc!pyramid!voder!apple!mikes From: mikes@apple.UUCP Newsgroups: comp.lang.c Subject: Re: Auto variable with sizeof == 0 Message-ID: <478@apple.UUCP> Date: Wed, 18-Feb-87 14:57:35 EST Article-I.D.: apple.478 Posted: Wed Feb 18 14:57:35 1987 Date-Received: Fri, 20-Feb-87 00:55:16 EST References: <4114@brl-adm.ARPA> <4053@utcsri.UUCP> <159@batcomputer.tn.cornell.edu> Reply-To: mikes@apple.UUCP (Mike Shannon) Organization: Apple Computer Inc., Cupertino, USA Lines: 27 We got bit by this one, where the user does struct Line { some overhead fields, like links, etc. char data[1]; /* actually, can be a lot more than one */ }; The idea was that the data part is at the end if struct Line, and can be VERY long. We were using a Green Hills C compiler, which had this nice feature of using 'short math' for certain array index calculations. Of course, when the 'data' got to be VERY long, short math won't do, and this caused some hard-to-find problems. Personally, I would incur the overhead of having an extra pointer in the structure, but if you really want to allocate the data *as part of struct Line*, then I am left with the feeling that the proper way to do this is: struct Line { overhead fields char data[MAX_IT_CAN_EVER_BE]; }; and allocate it via malloc(sizeof(struct Line) - MAX_IT_CAN_EVER_BE + sizeofyourdata) This isn't super clean, but I expect that for a language without dynamic arrays. -- Michael Shannon {apple!mikes}