segments and Unix

Jacob Gore gore at nucsrl.UUCP
Thu Nov 20 03:47:06 AEST 1986


> Have you ever spent a few days
> tracking down a bug caused by writing beyond the bounds of an array
> and trashing a vital data structure which only gets noticed many
> cycles later? [...]

Sigh... Who hasn't...

> Suppose every data structure were in its own segment. And of course,
> that every segment were big enough to hold any data structure you
> needed so that you didn't need to manage multiple segments for one
> data structure. Then when a bug trys to access beyond the end of an
> array, the bad reference is trapped at the time of dereference instead
> of invisibly (at the time) trashing an innocent data structure that
> happened to be in the right (wrong) place.
> 
> Would this be worth doing? [...]

Yes, but not this way.  It would not be accepted by hardware vendors.  The
makers of segment-oriented hardware always try to cram as much into each
segment as possible.  Why?  Because the overhead of switching segments makes
their benchmarks look worse.

Besides, there is a neat and simple software solution.  It is used in C++,
which, hopefully, will replace C eventually:  You can define a class
of arrays that always check that the index is within the boundaries.  Arrays
in this class are used in exactly the same way as normal arrays are used, so
it does not change the appearance of the program.

Jacob Gore
Northwestern University, Computer Science Research Lab
{ihnp4,chinet}!nucsrl!gore



More information about the Comp.lang.c mailing list