malloc impossible?

Jim Shankland jas at ernie.Berkeley.EDU
Fri Jan 13 04:47:45 AEST 1989


In article <9351 at smoke.BRL.MIL> gwyn at brl.arpa (Doug Gwyn (VLD/VMB) <gwyn>) writes:
>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.

Well, this is getting pretty esoteric, I suppose, but if I were implementing
(C - malloc) on such a machine, couldn't I reserve space for this union
in both fp space and integer space?  The value ouput by the printf above
would, of course, be entirely unaffected by the preceding assignment; but
as you say, the value printed is system-specific, anyway.  In other words,
are unions *required* to overlay their members onto the same physical
storage?

Jim Shankland
jas at ernie.berkeley.edu

"I've been walking in a river all my life, and now my feet are wet"



More information about the Comp.lang.c mailing list