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

  1. Newsgroups: comp.lang.c
  2. Path: sparky!uunet!usc!sdd.hp.com!think.com!yale.edu!ira.uka.de!fauern!lrz-muenchen.de!regent!pal
  3. From: pal@regent.e-technik.tu-muenchen.dbp.de (Peter Loibl)
  4. Subject: Re: pointer assignment problem
  5. Message-ID: <pal.724416939@regent.e-technik.tu-muenchen.de>
  6. Sender: news@regent.e-technik.tu-muenchen.de (News System)
  7. Organization: Technical University of Munich, Germany
  8. References: <1992Dec13.181118.2693@seas.gwu.edu> <Bz9Gxp.DMz@netnews.jhuapl.edu>
  9. Distribution: usa
  10. Date: Tue, 15 Dec 1992 10:55:39 GMT
  11. Lines: 30
  12.  
  13. bandy@netnews.jhuapl.edu (Mike Bandy) writes:
  14.  
  15. >saud@seas.gwu.edu (Temporary account (slc 11/19/92)) writes:
  16.  
  17. >>Hi:
  18.  
  19. >>I am having problem with pointer assignment 
  20.  
  21. >>look at this pleae
  22. >>    
  23. >>    function_node    *tmp_node;
  24.  
  25. >>    tmp_node = (function_node *) malloc (sizeof(tmp_node));
  26.  
  27. >Think about what tmp_node is; it's a pointer to a structure.  What gets
  28. >malloc'ed is (probably) 4 bytes of memory.  Stick a '*' in the sizeof
  29. >to tell it to allocate how much tmp_node _points to_ .  Like:
  30.  
  31. >    tmp_node = (function_node *) malloc (sizeof(*tmp_node));
  32.  
  33. If you have something like
  34. typedef struct function_node
  35. { ...
  36. } function_node;
  37.  
  38. then you can also write
  39.     tmp_node = (function_node *) malloc (sizeof(function_node));
  40.  
  41. Peter Loibl
  42. pal@regent.e-technik.tu-muenchen.de
  43.