signal 10 in malloc call???

Chris Torek chris at mimsy.UUCP
Wed May 18 21:33:32 AEST 1988


In article <350 at alice.marlow.reuters.co.uk> fox at alice.marlow.reuters.co.uk
(Paul Fox) provides a simple checking version of malloc.  Note that
it assumes that one can store a single `long' in the address returned
by malloc, and increment the result by the size of that long, and that
the resulting pointer is still `well aligned'.  As far as I can tell
there is no way to avoid some similar assumption.  It might be nice
to have an include file with a macro or function that aligns a pointer:

	#include <align.h>
	...
		void *p, *q;
		q = align(p);
	/* or possibly better */
		void *p; int off;
		off = align_off(p);

where <align.h> might read

	#define align(p) ((void *)(((long)(p) + 3) & ~3))

for a machine with four-byte alignment, or

	#define align_off(p) ((8 - ((long)(p) & 7)) & 7)

for a machine with eight-byte alignment, and maybe even

	int align_off(void *p);

for a machine with wacky alignment constraints.
-- 
In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7163)
Domain:	chris at mimsy.umd.edu	Path:	uunet!mimsy!chris



More information about the Comp.unix.wizards mailing list