Xref: utzoo comp.arch:14164 comp.lang.c:26217 Path: utzoo!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!uunet!ficc!peter From: peter@ficc.uu.net (Peter da Silva) Newsgroups: comp.arch,comp.lang.c Subject: Re: RISC Machine Data Structure Word Alignment Problems? Keywords: risc sun Message-ID: Date: 22 Feb 90 18:04:22 GMT References: <111@melpar.UUCP> <1990Jan21.224826.1699@esegue.segue.boston.ma.us> <1925@l.cc.purdue.edu> <645@mwtech.UUCP> Reply-To: peter@ficc.uu.net (Peter da Silva) Organization: Xenix Support, FICC Lines: 44 > (%): Even the guarantee, that the struct elements are at ascending > adresses in the order they are declared, IMHO only was given > to avoid complex (and hard to understand) rules, when and when > not it would be allowed to rearrange the elements. Readers who > know other good reasons why this guarantee is given are welcome > to correct me (hello Chris :-)). It makes the following two practices reasonably portable: 1: struct list_header { struct list_header next, prev; }; struct object { struct list_header list; ... }; struct list_header *my_list == NULL; struct object my_object; extern add_list(struct list_header **list, struct list_header *elt); add_list(&my_list, &my_object); 2: struct buffer { int len; char *next; char data[1]; }; struct buffer *new_buffer(size) int size; { struct buffer *temp; temp = (struct buffer *) malloc(sizeof *temp + size); if(temp) { temp->len = size; temp->next = &temp->data[0]; } return temp; } -- _--_|\ Peter da Silva. +1 713 274 5180. . / \ \_.--._/ Xenix Support -- it's not just a job, it's an adventure! v "Have you hugged your wolf today?" `-_-'