Article View: comp.os.msdos.programmer
Article #3726Re: C/C++7.0 .. 'null pointer assignments' .. but program's finished ! HELP!!
From: Stan Brown
Date: Sat, 10 Oct 1992 10:16
Date: Sat, 10 Oct 1992 10:16
41 lines
2758 bytes
2758 bytes
In article <BvsL61.LEE@resntl.bhp.com.au> Bernard Orenstein <bernie@resntl.bhp.com.au> writes: >in the past with C6.0, but now, under C7.0 is giving the >error "null pointer assignment" when it finishes executing >(and it does execute correctly) . I have used 'CodeView' to step through it, >which shows that after the last "}" in my main() program, it >goes off to execute some machine langiage instructions, a >call to some routine or other, and it is THIS call which gives >me the "null pointer assignement" error. "null pointer assignment" is described in the "Comprehensive Index and Error Messages" book that came with your C7.0 compiler. Your main program is not the beginning and end of the actual executable program. In fact, main( ) is a subroutine to the C startup code. That code does things like grab the command-line arguments and open stdin/stdout/stderr, then calls main( ), then upon return from main it closes any open files and checks for null pointer assignments. Pointers are not checked for validity when you actually use them; to do so would greatly add to the size of programs. Instead, Microsoft code checks after your program has executed whether 0000:0000 (*) has a different value from before it began. If so, your program must have written to it so Microsoft code tells you this. The actual assignment using an uninitialized pointer may have occurred at any point in the program. Your program did not execute correctly; it _appeared_ to execute correctly because the consequences of the failure were not obvious. The manual suggests that the code may fail in more obvious ways on different platforms. I add that "different platforms" means not just other (kinds of) machines but even the same machine if you have loaded different TSRs, or if a different program is executed before the one that gets "null pointer assignment". (*) If you're in small or medium memory model, data pointers are 16 bits and a null pointer would assign to location 0000 in your data segment, not to 0000:0000. I don't know the internals of how Microsoft code checks or what. But the general principles given above are correct based on my experience and reading the manuals. -- Stan Brown, Oak Road Systems brown@Ncoast.ORG Cleveland, Ohio, USA
Technical Details
Message-ID:
<BvwHw3.Fu2@NCoast.ORG>Path:
arc1-ca.pugleaf.net!sparky!uunet!spool.mu.edu!agate!usenet.ins.cwru.edu!ncoast!brownReferences:
<BvsL61.LEE@resntl.bhp.com.au>Show Full Headers
Complete Article Headers
Newsgroups: comp.os.msdos.programmer,comp.lang.c Path: arc1-ca.pugleaf.net!sparky!uunet!spool.mu.edu!agate!usenet.ins.cwru.edu!ncoast!brown From: brown@NCoast.ORG (Stan Brown) Subject: Re: C/C++7.0 .. 'null pointer assignments' .. but program's finished ! HELP!! Organization: Oak Road Systems, Cleveland Ohio USA Date: Sat, 10 Oct 1992 10:16:51 GMT Message-ID: <BvwHw3.Fu2@NCoast.ORG> References: <BvsL61.LEE@resntl.bhp.com.au> Lines: 41