Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!husc6!sri-unix!rutgers!rochester!PT!ius1.cs.cmu.edu!edw From: edw@ius1.cs.cmu.edu (Eddie Wyatt) Newsgroups: comp.lang.c Subject: Re: Arrays of Unknown Length in Structures (and sizeof) Message-ID: <1044@ius1.cs.cmu.edu> Date: Sun, 27-Sep-87 13:45:00 EDT Article-I.D.: ius1.1044 Posted: Sun Sep 27 13:45:00 1987 Date-Received: Tue, 29-Sep-87 03:39:31 EDT References: <243@mit-prep.ARPA> Organization: Carnegie-Mellon University, CS/RI Lines: 34 > struct STRUCT_FOO > { > int one; > int two; > int open[]; > }; > > foo_p = malloc(sizeof (struct STRUCT_FOO) + (7 * sizeof (int))); > > for (i = 0; i < 7; ++i) > foo_p->open[i] = i * 100; > ....... > I've tried this on two systems: VMS V4.5 running VAX C V2.3, and BSD 4.2 > running "cc". Both do what I want them to do, though "cc" gives a warning > message for line 6. > ..... > As far as I'm concerned, if this isn't kosher, it should be! Let me give you a reason of why this should not be "kosher". I don't think it is required in C that the fields in a structure be phyically ordered in the same ordering they are declared. Hence any of the 6 permutations of the fields you describe are valid for phyical offset orderings (ie open could have an offset of 0, two could have an offset of 0 and one could have an offset of 0 + sizeof(int)). This would wreak havoc!! -- Eddie Wyatt e-mail: edw@ius1.cs.cmu.edu