home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / comp / lang / c / 18331 < prev    next >
Encoding:
Text File  |  1992-12-14  |  1.0 KB  |  38 lines

  1. Newsgroups: comp.lang.c
  2. Path: sparky!uunet!netnews!bandy
  3. From: bandy@netnews.jhuapl.edu (Mike Bandy)
  4. Subject: Re: pointer assignment problem
  5. Message-ID: <Bz9Gxp.DMz@netnews.jhuapl.edu>
  6. Organization: JHU/Applied Physics Laboratory
  7. References: <1992Dec13.181118.2693@seas.gwu.edu>
  8. Distribution: usa
  9. Date: Mon, 14 Dec 1992 18:05:48 GMT
  10. Lines: 26
  11.  
  12. saud@seas.gwu.edu (Temporary account (slc 11/19/92)) writes:
  13.  
  14. >Hi:
  15.  
  16. >I am having problem with pointer assignment 
  17.  
  18. >look at this pleae
  19. >    
  20. >    function_node    *tmp_node;
  21.  
  22. >    tmp_node = (function_node *) malloc (sizeof(tmp_node));
  23.  
  24. Think about what tmp_node is; it's a pointer to a structure.  What gets
  25. malloc'ed is (probably) 4 bytes of memory.  Stick a '*' in the sizeof
  26. to tell it to allocate how much tmp_node _points to_ .  Like:
  27.  
  28.     tmp_node = (function_node *) malloc (sizeof(*tmp_node));
  29.  
  30. All the other problems you describe are due to running off past the
  31. end of the alloced space into illegal space.
  32.  
  33. -- 
  34.  
  35.     Mike Bandy
  36.     bandy@aplcomm.jhuapl.edu
  37.     Johns Hopkins University / Applied Physics Lab
  38.