Alignment of malloced memory (was: lint on malloc calls)

Steve C. Simmons scs at itivax.UUCP
Sun Sep 18 05:05:06 AEST 1988


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."



More information about the Comp.lang.c mailing list