🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.arch
Article #22549

Re: RISC Machine Data Structure Word Alignment Problems?

#22549
From: Peter da Silva
Date: Thu, 22 Feb 1990 18:04
49 lines
1785 bytes
> (%): 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@ficc.uu.net>.
/      \
\_.--._/ Xenix Support -- it's not just a job, it's an adventure!
      v  "Have you hugged your wolf today?" `-_-'
Technical Details
Message-ID: <D.X1XDFxds13@ficc.uu.net>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!uunet!ficc!peter
References: <111@melpar.UUCP> <1990Jan21.224826.1699@esegue.segue.boston.ma.us> <S_O1_F6xds13@ficc.uu.net> <1925@l.cc.purdue.edu> <645@mwtech.UUCP>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!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: <D.X1XDFxds13@ficc.uu.net>
Date: 22 Feb 90 18:04:22 GMT
References: <111@melpar.UUCP> <1990Jan21.224826.1699@esegue.segue.boston.ma.us> <S_O1_F6xds13@ficc.uu.net> <1925@l.cc.purdue.edu> <645@mwtech.UUCP>
Reply-To: peter@ficc.uu.net (Peter da Silva)
Organization: Xenix Support, FICC
Lines: 44