malloc impossible? (was: inkey$, noecho, and other impossibles)

Doug Gwyn gwyn at smoke.BRL.MIL
Thu Jan 12 15:08:29 AEST 1989


In article <15406 at mimsy.UUCP> chris at mimsy.UUCP (Chris Torek) writes:
>Actually, I was thinking about machines in which different types
>of objects must come from different address spaces (e.g., all
>`pointer' objects should be in the range 0x70000000..0x7c000000).

I still don't understand your example.  If C is to be implemented
on any architecture, the implementor has to arrange for pointers
to data objects to have the right properties, independently of
whether malloc looks something like:
	#define POOLMAX 10000
	static char pool[POOLMAX];
	static char *next = pool;
	void *malloc(size_t n) {
		register char *p;
		if (next - pool > POOLMAX - n)
			return NULL;
		p = next;
		next += n;	/* assume byte alignment is ok */
		return (void *)p;
	}
(Note -- I realize this is not a GOOD way to implement malloc, but
it is a POSSIBLE way, suitable for purposes of this discussion.
Naturally, one should implement malloc() better than this if at all
possible.)

Such an implementation of malloc() must work if the C language works.
That's why I claim that malloc() is implementable on all architectures
for which an implementation of C is feasible.



More information about the Comp.lang.c mailing list