Where are you malloc? I loc you still. Where are you?
Carl S. Gutekunst
csg at pyramid.pyramid.com
Sun Oct 8 03:15:55 AEST 1989
>>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.
<csg>
More information about the Comp.sys.pyramid
mailing list