[comp.lang.c] Any bounds-checking C compilers?

faustus@ic.Berkeley.EDU (Wayne A. Christopher) (06/23/88)

Are there any C compilers that compile in run-time bounds checking for array
accesses?  In some cases you couldn't do it, of course, but it would be nice
to be able to turn it on for those cases where it is possible.

	Wayne

barmar@think.COM (Barry Margolin) (06/24/88)

In article <4033@pasteur.Berkeley.Edu> faustus@ic.Berkeley.EDU (Wayne A. Christopher) writes:
>Are there any C compilers that compile in run-time bounds checking for array
>accesses?

The Symbolics C compiler, for Symbolics Lisp Machines, does various
kinds of bounds checking.  For malloc'ed data, it makes sure that you
don't reference outside the size you specified; i.e.

	ptr = malloc (10);
	foo = *(ptr + 11)

should generate an error.  For automatic variables, it checks that you
reference within the stack frame, but it doesn't check individual
arrays.

This bounds checking incurs little performance overhead, because it is
done by hardware array instructions, which do the checking in parallel
with the memory reference.

Barry Margolin
Thinking Machines Corp.

barmar@think.com
{uunet,harvard}!think!barmar

mkhaw@teknowledge-vaxc.ARPA (Mike Khaw) (06/25/88)

>Are there any C compilers that compile in run-time bounds checking for array
>accesses?

Catalytix's Safe-C compiler.  Catalytix is a company in Cambridge, MA (I
think).  I've never used Safe-C: just remember seeing ads for it.

Mike Khaw
-- 
internet: mkhaw@teknowledge.arpa
uucp:	  {uunet|sun|ucbvax|decwrl|uw-beaver}!mkhaw%teknowledge-vaxc.arpa
hardcopy: Teknowledge Inc, 1850 Embarcadero Rd, POB 10119, Palo Alto, CA 94303

john@uw-nsr.UUCP (John Sambrook) (07/02/88)

In article <4033@pasteur.Berkeley.Edu> faustus@ic.Berkeley.EDU (Wayne A. Christopher) writes:
>Are there any C compilers that compile in run-time bounds checking for array
>accesses?  In some cases you couldn't do it, of course, but it would be nice
>to be able to turn it on for those cases where it is possible.
>
>	Wayne
>
Disclaimer:

        I have no association with Data General other than being a consumer
        of their Unix products.  The C compiler is the best Unix C compiler
        I have ever used, and I have used a few.  In fact, the DG Unix C 
        compiler is a lot like having the IBM PL/I "Checkout" and "Optimizing"
        compilers rolled into one.  

The Data General C compiler can do this when requested via cc command 
line switches.  The compiler has a number of other features which make
it a real winner for porting existing code and for developing new code.

Another nice feature of this compiler and runtime system is that you
can compile in line number and procedure name information for use in
the event of a program abort.  Then, when your program does something
stupid, like dereferencing through NULL, you get a traceback that prints
line number and procedure name for each currently active procedure.  

There are a number of other useful options, like the ability to have
either signed or unsigned characters, and the ability to have zeroed
stack frames or not, and runtime pointer type checking for a certain
class of pointers ("byte" pointers v.s. "word" pointers).

-- 
John Sambrook                        Internet: john@nsr.bioeng.washington.edu
University of Washington RC-05           UUCP: uw-nsr!john
Seattle, Washington  98195               Dial: (206) 548-4386

                       ``Otium Cum Dignitate''