Path: utzoo!utgpu!water!watmath!clyde!rutgers!ames!oliveb!pyramid!voder!kontron!optilink!cramer From: cramer@optilink.UUCP (Clayton Cramer) Newsgroups: comp.lang.c Subject: Re: How to Trap Runtime System Error under MSC? Message-ID: <1854@optilink.UUCP> Date: 19 Jan 88 18:56:59 GMT References: <11279@brl-adm.ARPA> Organization: Optilink Corporation, Petaluma, CA Lines: 25 > Michael Harris asks, > > >Can anyone tell me how to trap Microsoft C "serious runtime errors", e.g., > >"Error 2000 Stack Overflow", before they print to the terminal screen? > > The answer to this is somewhat complex. > > Microsoft C uses a subroutine called "__chkstk" to allocate space for > temporaries on the stack. This routine also checks to determine whether the SP > register would be decremented below its lowest safe value, and prints the cited > error message if it is. Thus, there is no direct way to "trap" this in the > parent program. > > There is, however, light at the end of this tunnel. You could rewrite __chkstk > (use MASM, of course) to provide the kind of communication between the child and > the parent that you want, and rebuild your child program(s) using the __chkstk > object module to override inclusion of the Microsoft version of the routine. > > - Al You might find out if the $150 Microsoft charges for runtime library routine sources includes __chkstk. If not, take a look at the disassembled code from CodeView -- it's tiny. Clayton E. Cramer