Un-alignment in structures [mild flame]

Barry Shein root at bu-cs.UUCP
Sun Mar 17 10:02:21 AEST 1985


Ron, [note, I am not flaming at you, just a ref to your comment]

You say what galls you is the unnecessary padding on the VAX C,
what galls me more is the otherwise simple programs that won't
re-compile on our 3B5 cuz people played foot-loose and fancy-free
with the VAX's liberalness with alignment. Typical bad idiom:

struct string {
	short int length ;
	char *data ;
} ;
/* Obvious error checking omitted for brevity */
/* allocate space for a BCPL style string w/o calling malloc() too often */
struct string *
newstring(cp) char *cp ;
{
	static char *mypage = NULL ;
	struct string *sp ;

	if(mypage == NULL) mypage = (char *) malloc(LOTSAMEM) ;
	sp = (string *) mypage ;
	sp->length = strlen(cp) ;
	strcpy(sp->data,cp) ;
	mypage += sizeof(sp->length) + sp->length ;
	return(sp) ;
}

Looks wonderful, all full of fuzzy warm casts and types. Except
an odd length string leaves the next length on an odd boundary.
Sigh....[yes, the 3B5 then dies on the odd word ref]
	-Barry Shein, Boston University
P.S. Yes I know how to fix this by padding the sp->length to an even size.
Just tired of doing it, and even that is not safe for all machines.



More information about the Comp.lang.c mailing list