Path: utzoo!utgpu!attcan!uunet!lll-winken!ames!ncar!tank!mimsy!chris From: chris@mimsy.UUCP (Chris Torek) Newsgroups: comp.lang.c Subject: Re: malloc impossible? Message-ID: <15445@mimsy.UUCP> Date: 13 Jan 89 02:52:39 GMT References: <19@xenlink.UUCP> <225800106@uxe.cso.uiuc.edu> <310@twwells.uucp> <9351@smoke.BRL.MIL> Organization: U of Maryland, Dept. of Computer Science, Coll. Pk., MD 20742 Lines: 50 >In article <15427@mimsy.UUCP> I wrote: >>... I claim that, if the requirement for malloc() were dropped, one >>could implement C-minus-malloc on [more kinds of machines than now possible]. In article <9351@smoke.BRL.MIL> gwyn@smoke.BRL.MIL (Doug 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. And the code generated would be `allocate one object in each space, the double from F and the int from I' (that is, float and int spaces) rather than `allocate one object'. References to the union would write both spaces; pointers to unions would be represented as pairs. If we had a pointer to that union, the code generated for p->i = 123; might be something like (in vaxish assembly code) movq 4(ifp),r0r1 | pick up both halves of `p' | r0 holds &p->i; r1 holds &p->d movl $123,(r0:i) | write 123 in integer region movd $0d123.0,(r1:f) | write 123.0 in float region (The value written to the float region can almost be arbitrary, but it seems `cute' to assume that a compiler for this peculiar machine should convert the value being stored so as to wind up with the same value in each field. It makes the machine appear to use the same bit patterns for integers and floating point...! [Well, almost.]) Note that this implies that `void *' (and therefore `char *') pointers would have to be 8 bytes wide, since union pointers are actually pairs. >All data object types in C must be able to live in the same kind of space. Not in C-minus-malloc (and perhaps a few other functions I may have forgotten). I am fairly sure that the `core' part of the language can get away without this. varargs/stdarg does look hard. -- In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7163) Domain: chris@mimsy.umd.edu Path: uunet!mimsy!chris