Path: utzoo!attcan!uunet!husc6!mailrus!umich!itivax!scs From: scs@itivax.UUCP (Steve C. Simmons) Newsgroups: comp.lang.c Subject: Alignment of malloced memory (was: lint on malloc calls) Summary: What does the standard say? Keywords: lint, malloc, alignment Message-ID: <256@itivax.UUCP> Date: 17 Sep 88 19:05:06 GMT References: <39617@linus.UUCP> <9900007@bradley> <216@iaoobelix.UUCP> <7592@haddock.ima.isc.com> Reply-To: scs@itivax.UUCP (Steve C. Simmons) Organization: Industrial Technology Institute, Ann Arbor Lines: 26 All the discussion on the alignment of memory allocated by malloc is interesting, but only serves to point up that no matter what we try, the following lines of code are potentially non-portable: void *foo1 = malloc( 1 ) ; char *foo2 = malloc( foo2 ) ; short *foo3 = malloc( foo3 ) ; int *foo4 = malloc( foo4 ) ; long *foo5 = malloc( foo5 ) ; float *foo6 = malloc( foo6 ) ; double *foo7 = malloc( foo7 ) ; struct f *foo8 = malloc( foo8 ) ; So how do we fix it? A malloc call for every data type? How feasible is a tmalloc call like tmalloc( size, sizetype ) ; where sizetype is sizeof(type) for whatever we're allocating? Then we force alignment to the appropriate size in the tmalloc code, which is presumably machine-specific and understands the local needs. -- Steve Simmons ...!umix!itivax!vax3!scs Industrial Technology Institute, Ann Arbor, MI. "You can't get here from here."