RISC Machine Data Structure Word Alignment Problems?
Peter da Silva
peter at ficc.uu.net
Fri Feb 23 05:04:22 AEST 1990
> (%): 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. <peter at ficc.uu.net>.
/ \
\_.--._/ Xenix Support -- it's not just a job, it's an adventure!
v "Have you hugged your wolf today?" `-_-'
More information about the Comp.lang.c
mailing list