Xref: utzoo comp.std.c:1931 comp.lang.c:23176 Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!cs.utexas.edu!ginosko!brutus.cs.uiuc.edu!apple!altos!altos86!scott From: scott@altos86.Altos.COM (Scott A. Rotondo) Newsgroups: comp.std.c,comp.lang.c Subject: Re: commom malloc/free practice breaks standard - author strikes back Message-ID: <3695@altos86.Altos.COM> Date: 23 Oct 89 21:50:01 GMT References: <1989Oct16.111059.3840@anucsd.oz> <416@cpsolv.UUCP> <11334@smoke.BRL.MIL> <420@cpsolv.UUCP> Reply-To: scott@altos86.UUCP (Scott A. Rotondo) Followup-To: comp.std.c Organization: Altos Computer Systems, San Jose, CA Lines: 35 In article <420@cpsolv.UUCP> rhg@cpsolv.uucp (Richard H. Gumpertz) writes: > Arguments that just make assertions without citation don't hold much water. > I cannot find anything that says conversion from "void *" to "obj *" cannot > round up. In fact,I cannot find anything in the standard that says > free((void *) (object *) malloc(sizeof(object))) > will work: the standard only says that > free(malloc(sizeof(object))) > will work. Please tell me what section I have overlooked or stop saying > the standard already has things that I cannot find. 1. No one (to my knowledge) has claimed that conversion from "void *" to "obj *" is allowed to change the pointer's address if the "void *" is already aligned according to the requirements for "obj *". 2. Section 4.10.3 guarantees that the "void *" returned by malloc() is already aligned according to the requirements for "obj *", no matter what type "obj" represents. Therefore, no conversion from "void *" to "obj *" and back to "void *" can possibly change the pointer's address. Please note that the phrase "change the pointer's address" includes "rounding up" the address, but it does not include changing the format of the pointer without changing the address to which it points. The format of the pointer is irrelevant because it is visible only to the implementation. Anyone who wishes to continue this discussion will have to make the claim mentioned in paragraph 1 above, that a cast can modify a pointer address even if it is already aligned. I caution anyone who considers making this claim to read the Standard first. -- =============================================================================== Scott A. Rotondo, Altos Computer Systems (408) 946-6700 {sun|pyramid|uunet}!altos86!scott scott@Altos.COM