home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c
- Path: sparky!uunet!usc!sdd.hp.com!think.com!yale.edu!ira.uka.de!fauern!lrz-muenchen.de!regent!pal
- From: pal@regent.e-technik.tu-muenchen.dbp.de (Peter Loibl)
- Subject: Re: pointer assignment problem
- Message-ID: <pal.724416939@regent.e-technik.tu-muenchen.de>
- Sender: news@regent.e-technik.tu-muenchen.de (News System)
- Organization: Technical University of Munich, Germany
- References: <1992Dec13.181118.2693@seas.gwu.edu> <Bz9Gxp.DMz@netnews.jhuapl.edu>
- Distribution: usa
- Date: Tue, 15 Dec 1992 10:55:39 GMT
- Lines: 30
-
- bandy@netnews.jhuapl.edu (Mike Bandy) writes:
-
- >saud@seas.gwu.edu (Temporary account (slc 11/19/92)) writes:
-
- >>Hi:
-
- >>I am having problem with pointer assignment
-
- >>look at this pleae
- >>
- >> function_node *tmp_node;
-
- >> tmp_node = (function_node *) malloc (sizeof(tmp_node));
-
- >Think about what tmp_node is; it's a pointer to a structure. What gets
- >malloc'ed is (probably) 4 bytes of memory. Stick a '*' in the sizeof
- >to tell it to allocate how much tmp_node _points to_ . Like:
-
- > tmp_node = (function_node *) malloc (sizeof(*tmp_node));
-
- If you have something like
- typedef struct function_node
- { ...
- } function_node;
-
- then you can also write
- tmp_node = (function_node *) malloc (sizeof(function_node));
-
- Peter Loibl
- pal@regent.e-technik.tu-muenchen.de
-