Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!ames!lll-lcc!unisoft!mtxinu!sybase!forrest@sybase.com From: forrest@sybase.com Newsgroups: comp.sys.ibm.pc Subject: How Turbo C Handles Null Pointer Assignments Message-ID: <4178@sybase.sybase.com> Date: 10 May 89 00:34:41 GMT Sender: news@sybase.sybase.com Reply-To: forrest@sybase.com Organization: Sybase, Inc. Lines: 28 Sender:forrest@sybase.com I've just figured out some interesting facts about how Turbo C 2.0 detects null pointer assignments. Since this doesn't appear to be documented I thought I'd pass along what I've learned. All this started when I saw the message "Null Pointer Assignment" when running a program. This was surprising to me at first because I didn't know how a computer could detect null pointer assignments without using some kind of hardware memory protection scheme. After looking at the c0m.asm source code supplied with Turbo C I figured out what was going happening. Turbo C stores a check sum of the memory area starting with address 0 and continuing through where the message is stored that you see when you run Turbo C. As part of the _exit() procedure, this checksum is recomputed and compared to the original checksum. If you accidently put something in address 0 using a null pointer assignment these two values won't be the same a Turbo C prints the "Null Pointer Assignment" message. Although I haven't tried this yet, I think it would be possible to detect null pointer assignments at run time by setting a watchpoint on address 0 (I use the Turbo Debugger. I don't know if you can do this with the debugger that comes with Turbo C). Then, whenever the value at address 0 changes you will be notified. Jon Forrest forrest@sybase.com {pacbell,sun,{uunet,ucbvax}!mtxinu}!sybase!forrest 415-596-3422