🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.sys.amiga.tech
Article #6786

Re: Help. malloc() and SAS/C 5.10

#6786
From: Matthew Dillon
Date: Sat, 17 Nov 1990 18:29
43 lines
1960 bytes
In article <1990Nov15.164228.20119@ux1.cso.uiuc.edu> ragg0270@uxa.cso.uiuc.edu (Richard Alan Gerber) writes:
>Just when I think I'm beginning to get a glimmer of understanding concerning the
>C language, I realize I know nothing at all:
>
>I'm trying to port some NCSA HDF software to the Amiga. One header file
>defines:
>char *malloc();
>
>When I try to use that header file as well as stdlib.h from SAS/C 5.10,
>I get an external item mismatch error.
>
>So I look in stdlib.h. There I see:
>extern void *malloc __ARGS((unsigned));
>
>What's going on? What is this trying to tell me that malloc returns? It has to
>return a pointer to a memory location, right? I must be missing something.
>Perhaps this declaration aligns the memory so you can cast the pointer to any
>pointer type? Still, the manual says it returns a char *.

    malloc returns a 'void *' ... note that this is NOT a 'void', but a
    pointer to a 'void'.  Under ANSI, 'void *' is DEFINED to mean a
    'pointer to anything' and malloc is defined to return a pointer to
    any type of structure.  Thus, under ANSI, you can say:

    struct foo *foop = malloc(sizeof(struct foo));

    And the compiler will not give you a warning.  If malloc were declared
    as returning a 'char *', the compiler would give you warning for the
    above declaration.

						-Matt

>Totally lost,
>Richard Gerber
>gerber@rigel.astro.uiuc.edu

--


    Matthew Dillon	    dillon@Overload.Berkeley.CA.US
    891 Regal Rd.	    uunet.uu.net!overload!dillon
    Berkeley, Ca. 94708
    USA
Technical Details
Message-ID: <dillon.7264@overload.Berkeley.CA.US>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!wuarchive!uunet!overload!dillon
References: <1990Nov15.164228.20119@ux1.cso.uiuc.edu>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!wuarchive!uunet!overload!dillon
From: dillon@overload.Berkeley.CA.US (Matthew Dillon)
Newsgroups: comp.sys.amiga.tech
Subject: Re: Help. malloc() and SAS/C 5.10
Message-ID: <dillon.7264@overload.Berkeley.CA.US>
Date: 17 Nov 90 18:29:49 GMT
References: <1990Nov15.164228.20119@ux1.cso.uiuc.edu>
Lines: 43