Turbo C help wanted

Zhao yilin at caen.engin.umich.edu
Mon Oct 10 10:57:00 AEST 1988


In article <846.234EDDA6 at stjhmc.fidonet.org>, jim.nutt at p11.f15.n114.z1.fidonet.org (jim nutt) writes:
> 
> (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 with 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 
>  

I may have to repost my whole funciton again to avoid confusion. Please notice some omission of first posting.  

/*================================================================*/
/*   This function allocate a memory location for a node according
  to given information, i.e., start or new.
*/

TREEPTR create_node(info)
TREENODE  info;
   {                         
   TREEPTR  temp;

          temp = (TREEPTR)calloc(1, sizeof(TREENODE));
          if (!temp)                                               <== If out of memory, should be 
              printf("calloc error: empty pointer created!\n");    <== reported here!

          temp->num = info.num;
          temp->x = info.x;
          temp->y = info.y;  
          temp->forb = info.forb;
          temp->g = info.g;
          temp->next = NULL;
          return(temp);
   }
/*================================================================*/

I did use the way you sugessted. I also tried large and huge models when small did not work.   
Unfortunately, none of them works. "Null pointer assignment" only appears when we use EXIT(0)
instead of RETURN or when Version 1.5 is used. I even tried to test RETURN after each create_node().
The fact is after the 8th node was created, returning address was lost.  

I can list all of nodes just before program termination. If there is a null pointer assigned, 
can we print out the whole linked list?
 

Yilin Zhao
yilin at caen.engin.umich.edu



More information about the Comp.lang.c mailing list