Turbo C help wanted

jim nutt jim.nutt at p11.f15.n114.z1.fidonet.org
Fri Oct 7 17:36:59 AEST 1988


 > From: yilin at caen.engin.umich.edu (Zhao)
 > Message-ID: <3ee6a59e.14927 at asterix.engin.umich.edu>
 > parts in my posting. Actually, my key problem is I couldn't use RETURN 
 > although system
 > always give me "Null pointer assignment" error the final results are not 

bingo!  there's your problem... your assigning to a null pointer, which on pc compatible hardware has effects ranging from annoying to BRS (big red switch) time.

 > affected. The program  
 > did work when running on BSD4.2 unix system (DOMAIN C COMPILER) by using 
 > either RETURN or BREAK.
 > However Turbo C (1.5) doesn't take them. I couldn't believe this!!! My 

turbo c does accept return and break... the problem is the NULL pointer assignment.

 > friend and me have spent
 > several days and still don't know what is going on. It seems to us the 
 > return address is
 > lost after building linked list, but I still don't know how to fix it 
 > yet. When I compile the
 > code in Turbo C "Test stack overflow" option is ON and no "stack 
 > overflow" error message is
 > detected at run time. I doubt Turbo C compiler has some bugs.

i doubt it does not have bugs, but that's beside the point!


(bunches of irrelevant quoted code skipped)

 > >TREEPTR create_node(info)
 > >TREENODE info
 > >   {
 > >   TREEPTR temp;
 > >
 > >   temp = (TREEPTR)calloc(1, sizeof(TREENODE));
 > >   temp->num = info.num;
 > >   temp->x = info.x;
 > >   temp->y = info.y;
 > >   temp->next = NULL;
 > >   return(temp);
 > >   }

your problem is in this function.  what memory model are you using?  if small or medium model, you've less than 64k of heap space to play with and are probably running out of memory, thus calloc() returns NULL.  medium and small models are the ones in which a NULL pointer assignment is just annoying.  large or compact model on the other hand, means that a null pointer assignment is going straight into the interrupt vector table...  and that can ruin your day!  you need to check temp for NULL after the call



oc() and abort with an error if it comes up NULL.  it means you've run out of heap space.

jim nutt
'the computer handyman'



--  
St. Joseph's Hospital/Medical Center - Usenet <=> FidoNet Gateway
Uucp: ...{gatech,ames,rutgers}!ncar!noao!asuvax!stjhmc!15.11!jim.nutt



More information about the Comp.lang.c mailing list