malloc impossible?

Doug Gwyn gwyn at smoke.BRL.MIL
Fri Jan 13 02:21:24 AEST 1989


In article <15427 at mimsy.UUCP> chris at mimsy.UUCP (Chris Torek) writes:
>But I claim that, if the requirement for malloc() were dropped, one
>could implement C-minus-malloc on a machine that (say) required all
>floating point numbers to live in the floating-point address space,
>by having two stacks (one in the integer space and one in the fp space)
>and two data segments (likewise).

Assuming that integers could not also live in floating-point space,
C would not be implementable on such a hypothetical architecture.
Consider
	union	{
		double	d;
		int	i;
	}	u;
	u.d = 123.0;
	printf("%d\n", u.i);
This is required to work, although the specific value printed of course
depends on details of numeric representation on the specific system.
All data object types in C must be able to live in the same kind of space.
Whatever kind of space that is, is what one would parcel out via malloc().
Therefore malloc() is implementable if C is (at the very least, along the
lines I indicated in my previous example implementation).



More information about the Comp.lang.c mailing list