Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!yale!cmcl2!adm!smoke!gwyn From: gwyn@smoke.BRL.MIL (Doug Gwyn) Newsgroups: comp.std.c Subject: Re: malloc(0) Message-ID: <13472@smoke.BRL.MIL> Date: 3 Aug 90 03:17:14 GMT References: <1990Jul26.232216.15093@oresoft.com> <13441@smoke.BRL.MIL> <1990Jul31.222850.1873@oresoft.com> Organization: U.S. Army Ballistic Research Laboratory, APG, MD. Lines: 31 In article <1990Jul31.222850.1873@oresoft.com> dan@oresoft.com (Daniel Elbaum) writes: >If, on the other hand, two pointers are obtained from malloc2(0), their >values are known to be identical. They compare equal, but it's impossible >to say that they point to the same object, because what they point to isn't, >formally speaking, an object. It is, if the implementation provides this 0-sized object extension. >In short, the second approach has some merit. How (and why) is it >forbidden by the Standard? A strictly conforming program may not rely on malloc() supporting 0-sized objects at all. If some implementation provides such support as an extension, it should do so in a way that is consistent with the principles used in the standard. In this context, the most important principles are that pointers to distinct objects must not compare equal, and that each invocation of malloc() must allocate an object distinct from all other currently valid objects. I provide this just as guidance for implementors. Technically, such extensions are constrained by the standard only to the extent that they can be interpreted in terms of the basic standard. Since there are no explicit guidelines for 0-sized objects in the standard, some attributes of such objects in an extended implementation are subject to "judgement calls". As Point Of Contact for 0-sized objects, I've heard essentially all of the arguments pro and con each choice, and what I recommend is simply my best judgement concerning the matter. In particular, if programs are to make real use of 0-sized objects, they will benefit greatly if separately-malloc()ed ones do not seem to have equal pointers. Try writing some heavy-duty applications involving this stuff and see what I mean.