home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / comp / lang / c / 11704 < prev    next >
Encoding:
Text File  |  1992-07-29  |  1.6 KB  |  41 lines

  1. Newsgroups: comp.lang.c
  2. Path: sparky!uunet!cis.ohio-state.edu!zaphod.mps.ohio-state.edu!malgudi.oar.net!caen!destroyer!gumby!yale!mintaka.lcs.mit.edu!hal!mjd
  3. From: mjd@hal.gnu.ai.mit.edu (Sievan Janacziewski)
  4. Subject: Re: Pointers outside of array boundary
  5. Message-ID: <mjd.712419017@hal>
  6. Originator: mjd@hal.gnu.ai.mit.edu
  7. Sender: news@mintaka.lcs.mit.edu
  8. Organization: MIT Laboratory for Computer Science
  9. References: <1992Jul28.180945.22332@hubcap.clemson.edu>
  10. Date: Wed, 29 Jul 1992 14:10:17 GMT
  11. Lines: 28
  12.  
  13. mjs@hubcap.clemson.edu (M. J. Saltzman) writes:
  14.  
  15. >    float *x = malloc(10*sizeof(float));
  16. >    --x;
  17.  
  18. >which is supposed to give an array whose elements are addressed
  19. >as x[1]..x[10].
  20. >My question is: Can anyone name an existing machine on which this code
  21. >could fail, or give a really convincing hypothetical argument why it
  22. >is a bad idea?  My interlocutor claims the criticism of this form is
  23. >legalistic, and not based on practical considerations.
  24.  
  25. I was going to make up some thing about how maybe the array gets
  26. allocated at the top of memory, but there's a much better reason not to
  27. do this: C arrays always start at 0, never at 1, and by resorting to
  28. cute compiler hacks to fudge up the appearance of a 1-based array, one
  29. will only confuse oneself and other people who have to read,
  30. understand, maintain, and modify the code.
  31.  
  32. If 0-based arrays are unclear to your correspondent, then he or she
  33. should practice more, so that they become more familiar, rather than
  34. resorting to obfuscation to cover his or her inadequacies as a programmer.
  35.  
  36. This has nothing to do with legalism. 
  37. It is the most practical of all possible considerations.
  38.  
  39. Sievan Janacziewski
  40. mjd@gnu.ai.mit.edu
  41.