Run-time Checks for C
John Sambrook
john at uw-nsr.UUCP
Tue Nov 22 15:19:02 AEST 1988
In article <10113 at umn-cs.CS.UMN.EDU> raghavan at umn-cs.cs.umn.edu (Vijay Raghavan) writes:
>
> I made a casual statement in a local bulletin board to the effect that
>the C language definition doesn't really preclude any implementation from
>doing certain run-time checks (for array bounds, type checking, referring
>contents of uninitialized pointer variables &c), it's just that most
>(okay, all!) implementations don't do any such checking because of efficiency
>reasons. Now I'm not sure that this statement is really true (I mean I'm not
>sure that sufficient information can always be passed to the compiler for it
>to generate code for meaningful run-time checks.)
Please note that I have no relationship with Data General Corporation.
I just happen to think they have done a good job on their language
systems products.
The Data General C compiler is an example of a compiler that provides a
number of facilities for debugging programs, including several run time
checks. All such options are invoked with -C<option-name>.
Two useful switches are -Clineid and -Cprocid. They cause the compiler
to include source file line and procedure name information into the
generated code. If the program aborts a (stack) traceback is produced
that includes this information. Very useful.
-Csubcheck causes subscript range checking to be enabled. At run time
attempts to reference outside of an array are detected and the program
aborts (with a traceback). When possible the compiler detects these
errors at compile time.
-Cpointercheck is useful for catching uses of improperly typed pointers.
While not a fully general mechanism it does catch the types of errors that
cause programs to abort on MV series machines.
Finally, -Czeroframe causes the compiler to generate code to zero all
local variables when a new activation record (stack frame) is created.
This has been useful from time to time to track down uses of uninitialized
variables.
--
John Sambrook Internet: john at nsr.bioeng.washington.edu
University of Washington RC-05 UUCP: uw-nsr!john
Seattle, Washington 98195 Dial: (206) 548-4386
More information about the Comp.lang.c
mailing list