On Tue, 2003-10-07 at 07:59, Jacob Fugal wrote: > Bryan Murdock wrote: > > On Mon, 2003-10-06 at 20:51, Ross Werner wrote: > > > >>On Mon, 6 Oct 2003, Matt W. wrote: > >>"A friend" wants to know why we're so inconsistent with our > >>0-first/1-first counting methods. For example, if your program counts how > >>many tests have been taken and divides the total score, finding the > >>average, we have to start counting by one. (If we start at zero, we find > >>that dividing by zero is not very pretty.) On the other hand, arrays and > >>memory addressing start at zero. Why can't everything just start with one > >>or the other?! > >> > > > > It's not inconsistent. One is counting, the other is addressing. We'd > > be wasteful to not use zero as a valid address. > > Close, but it's even more clear. One is counting, the other is address > *offsetting*. It's not just wasteful, but incorrect, to leave out a > zero-byte offset.
Sorry, I was thinking hardware, where theoretically you could come up with whatever addressing scheme you want, but the most efficient schemes use _all_ the possible combinations of the bits you have available for your address, including 0 (or 00, or 000, etc.). As far as offsetting in a program, you could theoretically start with 1 and have the compiler know what to do with it. In perl there is an option (though it's use is highly discouraged) to have array offsets begin at 1. That's just plain weird though ;) Bryan ____________________ BYU Unix Users Group http://uug.byu.edu/ ___________________________________________________________________ List Info: http://uug.byu.edu/cgi-bin/mailman/listinfo/uug-list
