home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / lang / cplus / 16556 < prev    next >
Encoding:
Text File  |  1992-11-19  |  1.4 KB  |  32 lines

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