home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: sparky!uunet!cs.utexas.edu!zaphod.mps.ohio-state.edu!rpi!utcsri!helios.physics.utoronto.ca!alchemy.chem.utoronto.ca!mbersohn
- From: mbersohn@alchemy.chem.utoronto.ca (M. Bersohn)
- Subject: RUN TIME ARRAY INDEX ERRORS
- Message-ID: <1992Nov19.102258.4237@alchemy.chem.utoronto.ca>
- Sender: mbersohn@alchemy.chem.utoronto.ca (M. Bersohn)
- Organization: University of Toronto Chemistry Department
- Date: Thu, 19 Nov 1992 10:22:58 GMT
- Lines: 21
-
- Hello experienced people!
- There seem to be two ways to detect array index errors at
- run time. One is to explicitly check the index.
- int x[20];
-
- if (j >= 0 && j < 20 && function1(x[j]))
- ...
- The other way is the C++ way,to overload the [] operator.
- Explicit checks clutter the code enormously. The operator
- overloading method is transparent to us unless we remember the
- class definition. It's neat.
- My question to ask you is this: How did C survive all these
- years without such an obviously essential feature? How was
- anybody able to construct programs of 100,000 plus lines of C
- that worked well,without this feature? I'm a naive programmer;
- there is some magic there that escapes me.
- BTW using pointers to the array doesn't help. We still
- have to check the value of the offset.
- Thanks in advance for somebody's enlightened comment.
- Malcolm Bersohn
- mbersohn@alchemy.chem.utoronto.ca
-