🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.modula2
Article #4092

Re: 0-based/1-based arrays

#4092
From: Peter Schachte
Date: Thu, 03 Mar 1988 19:23
29 lines
1975 bytes
In article <2851@haddock.ISC.COM>, karl@haddock.ISC.COM (Karl Heuer) writes:
> When dealing with 0-based arrays, the appropriate concept is a half-open
> interval: the index for an N-element array comes from [0,N).  I find that this
> makes things simpler than with 1-based arrays, because half-open intervals can
> be abutted without having to adjust by one.  (I.e., [0,N) U [N,P) = [0,P).)

How is that any different than for 1-based arrays?

	[1,N) U [N,P) = [1,P), non?

In both of the rebuttals to the pro-1-based-array postings, I didn't see
anything that said where 1-based arrays fall down.  The only problem I
see with them is efficiency:  you have to subtract 1 (or 2 or 4 or
sizeof(element)) when you index into the array.  Or do you?  There's
nothing to say that the compiler can't actually allocate an array one
element bigger than you ask for, and just waste the first element, is
there?  If you've got the memory to burn.  C, of course would be in
trouble with this approach, since arrays in C are so often traversed by
pointer manipulation.  But in languages that don't allow this (and, I
hope, their compilers produce similar code anyway), there shouldn't be a
problem.

As someone said, one-based arrays often seem more natural.  I want to
store 10 of these things.  So I allocate a ten element array.  Now,
quick, which is the last element?  Number NINE?  Huh?
-- 
-Peter Schachte
pds@quintus.uucp
...!sun!quintus!pds
Technical Details
Message-ID: <726@sandino.quintus.UUCP>
Path: arc1-ca.pugleaf.net!utzoo!mnetor!uunet!lll-winken!lll-lcc!mordor!sri-spam!sri-unix!quintus!pds
References: <7161@sol.ARPA> <2740@mmintl.UUCP> <4343@june.cs.washington.edu> <2851@haddock.ISC.COM>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!mnetor!uunet!lll-winken!lll-lcc!mordor!sri-spam!sri-unix!quintus!pds
From: pds@quintus.UUCP (Peter Schachte)
Newsgroups: comp.lang.modula2,comp.lang.misc
Subject: Re: 0-based/1-based arrays
Message-ID: <726@sandino.quintus.UUCP>
Date: 3 Mar 88 19:23:47 GMT
References: <7161@sol.ARPA> <2740@mmintl.UUCP> <4343@june.cs.washington.edu> <2851@haddock.ISC.COM>
Organization: Quintus Computer Systems, Mountain View, CA
Lines: 28
Summary: How is that any different than for 1-based arrays?