home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!cs.utexas.edu!torn!cunews!revcan!micor!uuisis!synapse!rod.willmot
- From: rod.willmot@synapse.isis.org (Rod Willmot)
- Newsgroups: comp.lang.c
- Subject: structure question
- Message-ID: <225.1366.uupcb@synapse.isis.org>
- Date: 24 Jul 92 19:31:00 GMT
- Distribution: world
- Organization: SYNAPSE BBS - GATINEAU, QUEBEC - 819-561-4321
- Reply-To: rod.willmot@synapse.isis.org (Rod Willmot)
- Lines: 31
-
- TO: leegye@vuse.vanderbilt.edu
-
- To Gyesung Lee regarding his structure question:
-
- GL>main () /* create a global root and set next ptr to NULL */
- GL>{
- GL> Global_Root = (A_Type) malloc (sizeof(A_Type));
- GL> Global_Root->next = NULL;
- GL> abc();
- GL>}
- GL>The right answer should be:
- GL>In abc: is NULL
- GL>In abc1: is NULL
-
- Wrong! You only allocated one structure, therefore there is only
- one pointer to be NULL. The second output line expresses an
- attempt to test a pointer in a structure that was never allocated.
- You get a core dump because of an attempt to access an area of
- memory to which the program is denied access. Rearranging the
- elements of the structure only _seems_ to solve the problem, by
- accidentally making the invalid test point to an area of memory
- within the program's legitimate segment.
-
- To make your code bullet-proof, make sure that whenever a ->next
- pointer is NULL, there is no subsequent attempt to access the
- nonexistent structure to which it doesn't point!
-
- rod.willmot@synapse.isis.org (Rod Willmot)
- ---
- . DeLuxe. 1.20 #2423 .
-
-