Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.1 6/24/83; site bu-cs.UUCP Path: utzoo!linus!philabs!cmcl2!seismo!harvard!bu-cs!root From: root@bu-cs.UUCP (Barry Shein) Newsgroups: net.lang.c Subject: Re: Un-alignment in structures [mild flame] Message-ID: <250@bu-cs.UUCP> Date: Sat, 16-Mar-85 19:02:21 EST Article-I.D.: bu-cs.250 Posted: Sat Mar 16 19:02:21 1985 Date-Received: Mon, 18-Mar-85 04:02:49 EST References: <9239@brl-tgr.ARPA>, <9251@brl-tgr.ARPA> Organization: Boston Univ Comp. Sci. Lines: 33 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.