Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!husc6!bbn!rochester!PT!ius1.cs.cmu.edu!edw From: edw@ius1.cs.cmu.edu (Eddie Wyatt) Newsgroups: comp.lang.c Subject: Re: Order of fields (Was: Arrays of Unknown Length in Structures) Message-ID: <1047@ius1.cs.cmu.edu> Date: Thu, 1-Oct-87 09:54:03 EDT Article-I.D.: ius1.1047 Posted: Thu Oct 1 09:54:03 1987 Date-Received: Mon, 5-Oct-87 02:54:04 EDT References: <243@mit-prep.ARPA> <1044@ius1.cs.cmu.edu> <3043@ulysses.homer.nj.att.com> Organization: Carnegie-Mellon University, CS/RI Lines: 49 > > But it is. The version of the ANSI standard I have at hand (slightly > out of date but probably unchanged on this point) says(section > 3.5.2.1): > > Within a structure object, the non-bit-field members and the > units in which bitfields reside have addresses that increase in > the order in which they declared. > > K&R said the same thing in different words. > > Jerry Schwarz Sorry, the correct terminology I should have used is "member" not "field". As two people have pointed out, both K&R and the ANSI standard do dictate the the physical ordering of members of a structure. For those of you that complain about the size being unknown, I would say that the size of struct { char x; int open[]; } should be equal to the size of char + the number of bytes needed to align open on a valid integer boundary. I still have two complaints about what you are doing: 1. you can not validly pass by value the structure you have allocated. (you loose the array part). 2. what you are doing is a little obscure. There are posible alternatives to approximate what you need - declare the struct as follows : struct foo {char x; int open[MAX_OPEN_SIZE] } zz = (struct foo *) malloc(sizeof(struct foo)); or struct foo {char x; int *open} zz = (struct foo *) malloc(sizeof(struct foo)); zz->open = (int *) malloc(sizeof(int)*7); -- Eddie Wyatt e-mail: edw@ius1.cs.cmu.edu