home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / comp / lang / c / 11608 < prev    next >
Encoding:
Internet Message Format  |  1992-07-25  |  1.5 KB

  1. Path: sparky!uunet!cs.utexas.edu!torn!cunews!revcan!micor!uuisis!synapse!rod.willmot
  2. From: rod.willmot@synapse.isis.org (Rod Willmot) 
  3. Newsgroups: comp.lang.c
  4. Subject: structure question
  5. Message-ID: <225.1366.uupcb@synapse.isis.org>
  6. Date: 24 Jul 92 19:31:00 GMT
  7. Distribution: world
  8. Organization: SYNAPSE BBS - GATINEAU, QUEBEC - 819-561-4321
  9. Reply-To: rod.willmot@synapse.isis.org (Rod Willmot) 
  10. Lines: 31
  11.  
  12. TO: leegye@vuse.vanderbilt.edu 
  13.  
  14. To Gyesung Lee regarding his structure question:
  15.  
  16. GL>main  ()  /* create a global root and set next ptr to NULL */
  17. GL>{
  18. GL>  Global_Root = (A_Type) malloc (sizeof(A_Type));
  19. GL>  Global_Root->next = NULL;
  20. GL>  abc();
  21. GL>}
  22. GL>The right answer should be:
  23. GL>In abc:  is  NULL
  24. GL>In abc1: is  NULL
  25.  
  26. Wrong!  You only allocated one structure, therefore there is only 
  27. one pointer to be NULL.  The second output line expresses an 
  28. attempt to test a pointer in a structure that was never allocated.
  29. You get a core dump because of an attempt to access an area of 
  30. memory to which the program is denied access.  Rearranging the 
  31. elements of the structure only _seems_ to solve the problem, by 
  32. accidentally making the invalid test point to an area of memory
  33. within the program's legitimate segment.
  34.  
  35. To make your code bullet-proof, make sure that whenever a ->next 
  36. pointer is NULL, there is no subsequent attempt to access the 
  37. nonexistent structure to which it doesn't point!
  38.  
  39. rod.willmot@synapse.isis.org    (Rod Willmot)
  40. ---
  41.  . DeLuxe. 1.20 #2423 . 
  42.                                                                            
  43.