home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c
- Path: sparky!uunet!netnews!bandy
- From: bandy@netnews.jhuapl.edu (Mike Bandy)
- Subject: Re: pointer assignment problem
- Message-ID: <Bz9Gxp.DMz@netnews.jhuapl.edu>
- Organization: JHU/Applied Physics Laboratory
- References: <1992Dec13.181118.2693@seas.gwu.edu>
- Distribution: usa
- Date: Mon, 14 Dec 1992 18:05:48 GMT
- Lines: 26
-
- 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));
-
- All the other problems you describe are due to running off past the
- end of the alloced space into illegal space.
-
- --
-
- Mike Bandy
- bandy@aplcomm.jhuapl.edu
- Johns Hopkins University / Applied Physics Lab
-