Yet more on malloc and free and the proposed Standard

David Adrien Tanguay datanguay at watmath.waterloo.edu
Thu Dec 14 16:56:49 AEST 1989


In article <1989Dec12.234837.11020 at sq.sq.com> msb at sq.com (Mark Brader) writes:
 >
 >#         void *malloc (size_t size);
 >#
 >#   The malloc function allocates space for an object whose size is
 >#   specified by size ...
  [...]
 >#  The pointer returned ... 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 ...
 >
 >Notice the words "in the space allocated"!  While the words quoted in
 >4.10.3.3 do not forbid malloc() from using storage for its own internal
 >purposes, they do require that the size of the space allocated be what
 >the argument of malloc specifies.

It doesn't say that the size of the space allocated is "size", only that
the space allocated is "for an object whose size is ...",
meaning that the size of the space allocated is no smaller than "size".

 >The hypothetical implementation discussed above may be interpreted in
 >three ways, each of which violates some part of this.
 >
 >(a) The space allocated is 101 bytes, from 1345 to 1445.  This violates
 >    the "size specified" wording in 4.10.3.3.

Which is no longer violated under my interpretation above.

 >Thus the hypothetical implementation is NOT conforming, and so, this is
 >not a bug in the pANS.  Unless of course there's something that I've missed.

I don't think you've quite got it yet, but you're close.

David Tanguay



More information about the Comp.std.c mailing list