Path: utzoo!attcan!uunet!tut.cis.ohio-state.edu!rutgers!mephisto!ukma!randy From: randy@ms.uky.edu (Dan Chaney) Newsgroups: comp.lang.misc Subject: Re: Relationship between C and C++ Message-ID: <14649@s.ms.uky.edu> Date: 22 Mar 90 05:01:20 GMT References: <8432@hubcap.clemson.edu> <5200048@m.cs.uiuc.edu> Reply-To: randy@ms.uky.edu (Randy Appleton) Organization: U of Kentucky, Mathematical Sciences Lines: 41 In article <5200048@m.cs.uiuc.edu> robison@m.cs.uiuc.edu writes: >This is not the first attack on pointer arithmetic that I have seen. >Why is pointer arithmetic denigrated so much? The C-style pointer >arithmetic seems to me to implement a fairly simple abstraction, >roughly equivalent to ``a tape and a read/write head.'' >Most C implementations do not do bounds checking on pointers, >but I fail to see why pointer arithmetic is inherently evil. > >Can anyone clue me as to the basis for pointer paranoia? I belive the whole thing can be illustrated with one example. I was writing a client as a programming assignment just yesterday, and I ran into a strange bug. A variable I though was limited 0..4 was very occasionaly getting values in the 10,000's. It turned out, in a different file far away from this variable, I was calulating the length of a buffer off by one, and I was overwriting the first byte of the variable. Most of the time, it was a zero overwriting a zero, but not always. To make things worse, I could not use the 'trace' feature of dbx because that slooows things way down, and in networking things happen in real time. I was sure that I had a pointer error, but it was NOT obvious where, or what to do. Yes, this was a programming error on my part. And yes, I know "only experts should use C", but then again I think I'm an O.K C programmer. The problem with pointer arithmatic without range checking is that this sort of error will occure from time to time, even for "experts", and it is very hard to fix. P.S. For the guy who wanted bug stories, here's mine. Randy -- ---------------------------------------------------------------------------- Woody Allen: "Your skin, it is so beautiful!" Mia Farrow: "Yes, and it covers my whole body, too" -----------------Randy Appleton - randy@ms.uky.edu--------------------------