Xref: utzoo comp.std.c:1958 comp.lang.c:23342 Path: utzoo!utgpu!utstat!jarvis.csri.toronto.edu!mailrus!uwm.edu!gem.mps.ohio-state.edu!ginosko!xanth!cs.odu.edu!kremer From: kremer@cs.odu.edu (Lloyd Kremer) Newsgroups: comp.std.c,comp.lang.c Subject: Re: Common malloc/free practice violates ANSI standard ? Message-ID: <10282@xanth.cs.odu.edu> Date: 26 Oct 89 19:50:56 GMT References: <1989Oct14.043811.669@anucsd.oz> <1989Oct19.101306.16791@twwells.com> <423@cpsolv.UUCP> <1989Oct24.194920.7250@twwells.com> Sender: news@cs.odu.edu Followup-To: comp.std.c Organization: Old Dominion University, Norfolk, VA Lines: 32 I will try to shed some additional light on this, although I may be a fool to attempt it. :-) There is a fundamental difference between void * and void * returned by malloc (or any allocation routine). In one sense they are opposites. A void* in general has the most lenient alignment requirements of any data pointer. A void* returned by malloc has the most stringent. OBJ* -> void* -> OBJ* is true for any void*. void* -> OBJ* -> void* is not true for general void*, but is guaranteed true for void* returned by malloc. void* is required to be physically identical to char*. In some implementations (word oriented architectures), a char* is physically bigger (has more bits) than pointers to some other objects. A char* contains a word address and then a byte offset within the word. Hence a cast from a general void* to a smaller pointer type can irreversibly lose data. A void* returned from malloc is guaranteed to have these additional bits zero, so the truncation is harmless. Lloyd Kremer kremer@cs.odu.edu Have terminal...will hack!