Path: utzoo!utgpu!news-server.csri.toronto.edu!mailrus!cs.utexas.edu!sdd.hp.com!uakari.primate.wisc.edu!aplcen!uunet!mcsun!ukc!warwick!nott-cs!christopher-robin.cs.bham.ac.uk!cjr From: cjr@cs.bham.ac.uk (Chris Ridd ) Newsgroups: comp.lang.c Subject: Re: Array bounds checking with C???? Message-ID: <988@christopher-robin.cs.bham.ac.uk> Date: 30 Aug 90 10:21:50 GMT References: <7611@ucdavis.ucdavis.edu> <26196@mimsy.umd.edu> Reply-To: cjr@christopher-robin.UUCP (Chris Ridd ) Organization: University of Birmingham, England Lines: 23 In article <26196@mimsy.umd.edu> chris@mimsy.umd.edu (Chris Torek) writes: >In article <7611@ucdavis.ucdavis.edu> kuan@iris.ucdavis.edu >(Frank [Who me?] Kuan) writes: >>Why is it that most C compilers don't seem to [check array bounds]? > >Mostly because it is hard. Given `int *p', is `p[-1] = 3' valid? >That depends on the value of p.... > >There is a company called Saber that produces a product called >Saber-C that does this and more. It works quite well, although last >I had heard it still objected to `&arr[sizeof arr/sizeof *arr]', >which is Officially Legal. (Fortunately you can turn off each >individual objection.) Why is this? I never could figure out why accessing the first element *past* the end of an array should be legal. Chris -- Chris Ridd, Computer Science, Birmingham Uni, UK -- RiddCJ@Cs.Bham.Ac.Uk -- "'It's going to look pretty good, then, isn't it,' said War testily, 'the One Horseman and Three Pedestrians of the Apocralypse.'" - Sourcery