scs@itivax.UUCP (Steve C. Simmons) (09/18/88)
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."
gwyn@smoke.ARPA (Doug Gwyn ) (09/18/88)
In article <256@itivax.UUCP> scs@itivax.UUCP (Steve C. Simmons) writes: >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: >... >char *foo2 = malloc( foo2 ) ; >... "Incomprehensible" might be a better description. What are you trying to say/ask? malloc() most certainly can be used portably: /* (declarations omitted) */ obj_ptr = (obj *)malloc( how_many * sizeof(obj) );