Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!uwm.edu!gem.mps.ohio-state.edu!ginosko!rex!ukma!husc6!ncar!jsloan@handies.ucar.edu From: jsloan@handies.ucar.edu (John Sloan,8292,X1243,ML44E) Newsgroups: comp.sys.pyramid Subject: Re: Where are you malloc? I loc you still. Where are you? Message-ID: <4624@ncar.ucar.edu> Date: 6 Oct 89 19:34:04 GMT References: <86743@pyramid.pyramid.com> Sender: news@ncar.ucar.edu Lines: 30 From article <86743@pyramid.pyramid.com>, by csg@pyramid.pyramid.com (Carl S. Gutekunst): > 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? The only possible choice would be "char *malloc" since it returns a pointer. 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". That's all well and good, but what if you're developing something big in which ALL malloc's are for some structure other than a character string. Now on all instances of malloc you gotta cast it to the correct thing. Wouldn't it be simpler just to declare malloc to be "struct node *malloc" in some master header file? But you can't do that, 'cause cc will complain about the redeclaration. Without any specified declaration in some malloc.h, you can declare malloc to be anything you want, and cast it only when necessary. It's a lame excuse, I admit. What you need is something like C++'s "void *", where you mean "It's a pointer, darn it, just an address, don't bug me about it". John Sloan NCAR/SCD NSFnet: jsloan@ncar.ucar.edu P.O. Box 27588 P.O. Box 3000 NCAR Mesa Lab, Room 42A Lakewood CO 80227 Boulder CO 80307 +1 303 497 1243 Logical Disclaimer: belong(opinions,jsloan). belong(opinions,_):-!,fail.