home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #1 / NN_1993_1.iso / spool / comp / lang / c / 19307 < prev    next >
Encoding:
Text File  |  1993-01-06  |  2.0 KB  |  47 lines

  1. Newsgroups: comp.lang.c
  2. Path: sparky!uunet!stanford.edu!nntp.Stanford.EDU!dkeisen
  3. From: dkeisen@leland.Stanford.EDU (Dave Eisen)
  4. Subject: Re: Moving from Pascal to C, Help please!!!!!!
  5. Message-ID: <1993Jan6.151028.2055@leland.Stanford.EDU>
  6. Sender: news@leland.Stanford.EDU (Mr News)
  7. Organization: Sequoia Peripherals, Inc.
  8. References: <C04E63.863@newcastle.ac.uk> <1993Jan5.162504.1680@leland.Stanford.EDU> <4293@dozo.and.nl>
  9. Date: Wed, 6 Jan 93 15:10:28 GMT
  10. Lines: 35
  11.  
  12. In article <4293@dozo.and.nl> jos@and.nl (Jos Horsmeier) writes:
  13.  
  14. >Then you've just been plain lucky and so were the authors of NRC. 99%
  15. >of all their pointer fiddling (subtracting the lowest index value from a
  16. >pointer) is done with an offset of one. Imagine a segmented memory
  17. >architecture as used in a PC. Global arrays are almost never stored
  18. >at the beginning of a segment, so the offset of the address of such
  19. >an array is always larger than one. Pointer arithmetic is almost always
  20. >done using the offset. The segment value is ignored. The same thing is
  21.  
  22. My understanding was that Numerical recipes in C used the trick:
  23.  
  24. #define   Array      (array - 1)
  25.  
  26. and then indexed the array as Array[1] to Array[n-1].
  27.  
  28. Yes, array - 1 is illegal. Even when used as Array[1] which
  29. is the same as *(array - 1 + 1). But even if a system uses
  30. segments in such a way that array - 1 is not a valid address,
  31. it is very likely that array - 1 + 1 gives a pointer that
  32. is represented exactly the same way as array is. Even if pointer
  33. arithmetic is done using only the offset.
  34.  
  35. Don't take any of this as an endorsement of this "technique". It
  36. isn't. I just said that it was not enough to keep me from buying
  37. the book. It is not something I would ever do in my own code; I
  38. try to stay out of the areas of undefined behavior.
  39.  
  40.  
  41.  
  42. -- 
  43. Dave Eisen                               Sequoia Peripherals: (415) 967-5644
  44. dkeisen@leland.Stanford.EDU              Home:                (415) 321-5154
  45.        There's something in my library to offend everybody. 
  46.           --- Washington Coalition Against Censorship
  47.