TC 2.0 oddity - me or it ?

house ron s64421 at zeus.usq.EDU.AU
Tue Nov 13 20:50:04 AEST 1990


djm at castle.ed.ac.uk (D Murphy) writes:

>I have a program running on a PC which does its job perfectly BUT which 
>produces a Null pointer assignment message after it has finished. This
>is being caused by something after the last instruction (I tested this
>by adding puts("Last"); just before the closing brace of main() and got

>Last
>Null pointer assignment

Zero is actually a perfectly legitimate address, but it got snaffued
by C to stand for a NULL pointer.  Thus, if in your program you do:

    int *p = NULL;
    *p=9;

You will happily store 9 in address zero.  The compiler doesn't write logic
to check for this because it would slow you down.  But when the prog.
finishes, it does just a single check on address zero to see if you
changed it.

You should be able to easily write a small test prog. to verify this.
--
Regards,

Ron House.   (s64421 at zeus.usq.edu.au)
(By post: Info Tech, U.C.S.Q. Toowoomba. Australia. 4350)



More information about the Comp.lang.c mailing list