commom malloc/free practice breaks standard - author strikes back

Scott A. Rotondo scott at altos86.Altos.COM
Thu Oct 19 07:39:27 AEST 1989


Brendan: I have trouble with both "most restrictive alignment" (only
	 used by the standard as a property of types, not of pointer
	 values) and "address unchanged" (see part (B) above).

Types have alignment restrictions.  The same restrictions apply to the
addresses represented by pointers to objects which have types.
Malloc() must return pointers whose addresses meet the most restrictive
of these alignment requirements.

Brendan: No doubt this problem was unintentional.  It could easily be
	 fixed by a sentence reading something like "The pointer
	 returned if the allocation succeeds is such that, if it is
	 cast to a pointer to any type of object and then that pointer
	 is cast to type void*, the original value is recovered."
Scott:   This is precisely the meaning of the section 4.10.3 alignment
	 rule.
Brendan: The intention, I'm sure.  The meaning is another matter.

Section 4.10.3 doesn't simply state that you must be able to cast or assign
the pointer and use it; it says that you must be able to use the pointer
because it is "suitably aligned."  Your hypothetical implementation only
meets the weaker of these two conditions.
-- 
===============================================================================
Scott A. Rotondo, Altos Computer Systems			 (408) 946-6700

{sun|pyramid|uunet}!altos86!scott				scott at Altos.COM	



More information about the Comp.lang.c mailing list