Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!wuarchive!gem.mps.ohio-state.edu!apple!voder!pyramid!csg From: csg@pyramid.pyramid.com (Carl S. Gutekunst) Newsgroups: comp.sys.pyramid Subject: Re: Where are you malloc? I loc you still. Where are you? Message-ID: <86859@pyramid.pyramid.com> Date: 7 Oct 89 17:15:55 GMT References: <86743@pyramid.pyramid.com> <4624@ncar.ucar.edu> Reply-To: csg@pyramid.pyramid.com (Carl S. Gutekunst) Organization: Pyramid Technology Corp., Mountain View, CA Lines: 21 >>Now, if you want to know why *Berkeley* didn't put a declaration of malloc(3) >>in some convenient header file, I haven't any idea. But I agree it would be a >>good idea. > >Here's a guess: What would you declare it as? You'd declare it as a its declared type: char *. Anything else would be wrong. >But even though perhaps 75% of the time you are allocating a character >string, 25% of the time you're allocating some other data type, most likely >a structure. So to keep cc from complaining, you gotta cast the output of >malloc into another type, e.g. "(struct node *)malloc". Yup. And that is the *ONLY* correct way to do it. Those of us living on nice contiguous memory, byte-addressable architectures have gotten terribly spoiled by the fact that pointers are the same, no matter what they are pointing to. But that ain't the case everywhere. malloc(3) returns a char *. If you are on the wrong machine (Sperry 2200 and Cyber come to mind), and you simply declare malloc() are something else, you software will crash and burn.