🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c
Article #781

Re: malloc/free practice - more from the author

#781
From: Doug Gwyn
Date: Thu, 19 Oct 1989 10:36
27 lines
2088 bytes
In article <1989Oct17.033415.16036@anucsd.oz> bdm@anucsd.oz (Brendan McKay) writes:
>The only alignment requirement made for the value of malloc() is THAT IT
>IS SUITABLE FOR USE *AFTER CASTING*. ... read the standard again.
>Yes, this is maybe just an exercise in pedantry.  Well-written standards
>should survive such exercises, though.

If you had constructive comments on the wording used in the proposed
Standard, you should have made them during the public review phase
when there would have been some chance that we would have performed
some "wordsmithing" to clarify points that may have confused you.

However, since we're being pedantic here, I'll point out that the
Standard does NOT state what you capitalized.  What is does say is,
"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 array of such objects in the
space allocated ... The pointer returned points to the start (lowest
byte address) of the allocated space."  You appear to have jumped on
the first sentence without considering its context.  The second
sentence I cited makes it clear that the pointer that malloc()
returns is ITSELF already suitably aligned; no conversion is
necessary to ensure that.  The reason we say "may be assigned to a
pointer..." is that the void* returned by malloc(), like any void*,
itself is NOT a pointer to an "object" in the formal C sense,
although it does point to the start of allocated space.

P.S.  As usual, this is not an official X3J11 response.
Technical Details
Message-ID: <11340@smoke.BRL.MIL>
Path: arc1-ca.pugleaf.net!utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!uwm.edu!gem.mps.ohio-state.edu!uakari.primate.wisc.edu!aplcen!haven!adm!smoke!gwyn
References: <1989Oct17.033415.16036@anucsd.oz>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!uwm.edu!gem.mps.ohio-state.edu!uakari.primate.wisc.edu!aplcen!haven!adm!smoke!gwyn
From: gwyn@smoke.BRL.MIL (Doug Gwyn)
Newsgroups: comp.std.c
Subject: Re: malloc/free practice - more from the author
Message-ID: <11340@smoke.BRL.MIL>
Date: 19 Oct 89 10:36:37 GMT
References: <1989Oct17.033415.16036@anucsd.oz>
Reply-To: gwyn@brl.arpa (Doug Gwyn)
Organization: Ballistic Research Lab (BRL), APG, MD.
Lines: 27