Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!caen!hellgate.utah.edu!csn!pikes!aspen.craycos.com!jrbd From: jrbd@craycos.com (James Davies) Newsgroups: comp.lang.c Subject: Re: casting void pointers Message-ID: <1991Apr23.161345.4758@craycos.com> Date: 23 Apr 91 16:13:45 GMT References: <3121@enuxha.eas.asu.edu> <4256@rwthinf.UUCP> Organization: Cray Computer Corporation Lines: 14 In article <4256@rwthinf.UUCP> berg@marvin.e17.physik.tu-muenchen.de (Stephen R. van den Berg) writes: >Roger A. Hurwitz writes: >>Even K&R 2d states that an explicit cast should be used with malloc(), >>in another part of the book (p. 142), but I am having trouble reconciling >>that with the above language. > >malloc does not need the cast, any compiler complaining about that is >braindamaged (or not ANSI compliant :-) In fact, the cast can actually be damaging. If you forget to declare malloc on a 16-bit-int machine like a PC, but then cast the returned value, most compilers will assume you know what you're doing and quietly strip off the high 16 bits of your 32-bit pointer. (I once spent two days finding a bug like this...)