Turbo C help wanted

Shawn Willden swillden at wsccs.UUCP
Fri Oct 14 04:16:09 AEST 1988


In article <3ef69894.14927 at asterix.engin.umich.edu>, yilin at caen.engin.umich.edu (Zhao) writes:
> 
> 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 didn't get your original posting, so I don't know all the details, but
I use Turbo C quite exstensively (6-8 hrs./day) and I have run into a
problem similar to yours.  I don't remember how I fixed it, but I found
some ways to avoid it.

There may be a problem with your
structure passing.  Turbo C _should_ allow passing of a structure by
value because it is supposed to be ANSI C compatible, but it is more
portable and works.  I would suggest you pass info by pointer (since
your code never modifies info, that is not a problem) and use function
prototyping.  With prototyping, TC will automatically do all kinds of
great type checking and type conversions for you when you make function
calls.  In other words, use:

	TREEPTR creatnode (TREENODE *info);

and pass the address of info.

Those are just some suggestions that are probably not your problem but
make debugging easier.

If Turbo C gives you a NULL POINTER ASSIGNMENT error, that error could
have occurred at any time, not necessarily just before termination.  I
once had a program that executed fine for a good ten minutes after the
error occurred.  It gave me a null point assign error when it
terminated.  When I finally traced the bug down and found the place
where the null point assign had actually taken place, it turned out to be
in a function call from another source code file that was one of the
first to be executed!  That's probably not very encouraging.  I'm just
pointing out that your error could be somewhere else.

If you'd like to e-mail me your source code, I can probably find the bug
(I've had much experience at tracing reclusive bugs in TC) or at least
give you some ideas as to where to look.

swillden at wsccs

--------------------------------------------
I know I know something.  I'm just not sure what.
---------------------------------------------------

disclaimer:  Since I don't even see my employers more than an hour or so
a week, I can't very well be expected to have ALL their opinions changed
to mine, can I?



More information about the Comp.lang.c mailing list