Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!rutgers!clyde!cbatt!ihnp4!chinet!nucsrl!gore From: gore@nucsrl.UUCP (Jacob Gore) Newsgroups: comp.lang.c Subject: Re: segments and Unix Message-ID: <3950002@nucsrl.UUCP> Date: Wed, 19-Nov-86 12:47:06 EST Article-I.D.: nucsrl.3950002 Posted: Wed Nov 19 12:47:06 1986 Date-Received: Fri, 21-Nov-86 00:56:25 EST References: <13802@amdcad.UUCP> Organization: Northwestern Univ., Evanston IL Lines: 31 > 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