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