Where are you malloc? I loc you still. Where are you?

John Sloan,8292,X1243,ML44E jsloan at handies.ucar.edu
Sat Oct 7 05:34:04 AEST 1989


>From article <86743 at pyramid.pyramid.com>, by csg at 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 at 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.



More information about the Comp.sys.pyramid mailing list