commom malloc/free practice breaks standard - author strikes back

David Adrien Tanguay datanguay at watmath.waterloo.edu
Fri Oct 20 20:44:30 AEST 1989


In article <992 at cirrusl.UUCP> dhesi%cirrusl at oliveb.ATC.olivetti.com (Rahul Dhesi) writes:
>I, like many others, rely on the gurus in comp.lang.c for much valuable
>information.  Can somebody quote chapter and verse to show that the
>standard does require the series of casts
>
>     void * ->  OBJ *  ->  void *
>
>to yield the original pointer?

For a general pointer this is not the case, but the argument is about
pointers returned by malloc. From section 4.10.3 "Memory management functions":

	The pointer returned if the allocation succeeds is suitably aligned
	so that it may be assigned to a pointer to any type of object and
	then used to access such an object or an array of such objects in
	the space allocated (until the space is explicitly freed or
	reallocated). Each such allocation shall yield a pointer to an
	object disjoint from any other object. The pointer returned points
	to the start (lowest byte address) of the allocated space.

I don't see anything there (or anywhere in 4.10.3.*) that asserts the above
series of casts.

David Tanguay



More information about the Comp.lang.c mailing list