Rocksolid Light

Welcome to RetroBBS

mail  files  register  newsreader  groups  login

Message-ID:  

The documentation is in Japanese. Good luck. -- Rich $alz


devel / comp.lang.fortran / Re: “Why do arrays start at 0?"

SubjectAuthor
* “Why do arrays start at 0?"Lynn McGuire
+* Re: “Why do arrays start at 0?"Gary Scott
|+* Re: “Why do arrays start at 0?"Mr Flibble
||`* Re: “Why do arrays start at 0?"d thiebaud
|| +- Re: “Why do arrays start at 0?"gah4
|| +- Re: “Why do arrays start at 0?"Robin Vowels
|| `* Re: “Why do arrays start at 0?"Keith Thompson
||  `- Re: “Why do arrays start at 0?"Mr Flibble
|+- Re: “Why do arrays start at 0?"gah4
|+- Re: Re: “Why do arrays start at 0?"Scott Lurndal
|`- Re: ?Why do arrays start at 0?"Charlie Roberts
+* Re: “Why do arrays start at 0?"Louis Krupp
|`* Re: ?Why do arrays start at 0?"Charlie Roberts
| +- Re: “Why do arrays start at 0?"Thomas Koenig
| `* Re: “Why do arrays start at 0?"Ron Shepard
|  `* Re: “Why do arrays start at 0?"Thomas Koenig
|   `- Re: “Why do arrays start at 0?"gah4
+- Re: “Why do arrays start at 0?"Mr Flibble
+* Re: “Why do arrays start at 0?"Robin Vowels
|`* Re: “Why do arrays start at 0?"fiz...@gmail.com
| +* Re: “Why do arrays start at 0?"gah4
| |`* Re: “Why do arrays start at 0?"Thomas Koenig
| | `* Re: “Why do arrays start at 0?"gah4
| |  `* Re: “Why do arrays start at 0?"Thomas Koenig
| |   +* Re: “Why do arrays start at 0?"gah4
| |   |+- Re: “Why do arrays start at 0?"Thomas Koenig
| |   |`* Re: “Why do arrays start at 0?"Lynn McGuire
| |   | +* Re: “Why do arrays start at 0?"Thomas Koenig
| |   | |`- Re: “Why do arrays start at 0?"gah4
| |   | +* Re: “Why do arrays start at 0?"gah4
| |   | |`- Re: “Why do arrays start at 0?"Robin Vowels
| |   | `- Re: “Why do arrays start at 0?"Robin Vowels
| |   `* Re: “Why do arrays start at 0?"Ron Shepard
| |    +* Re: “Why do arrays start at 0?"Robin Vowels
| |    |`* Re: “Why do arrays start at 0?"Ron Shepard
| |    | `- Re: “Why do arrays start at 0?"Robin Vowels
| |    `- Re: “Why do arrays start at 0?"gah4
| `- Re: “Why do arrays start at 0?"Robin Vowels
+* Re: “Why do arrays start at 0?"Thomas Koenig
|`* Re: “Why do arrays start at 0?"d thiebaud
| +- Re: “Why do arrays start at 0?"FortranFan
| `- Re: “Why do arrays start at 0?"Thomas Koenig
+* Re: “Why do arrays start at 0?"Fred. Zwarts
|`* Re: “Why do arrays start at 0?"Lynn McGuire
| +* Re: “Why do arrays start at 0?"Thomas Koenig
| |+* Re: “Why do arrays start at 0?"John
| ||`- Re: “Why do arrays start at 0?"Robin Vowels
| |`* Re: “Why do arrays start at 0?"Lynn McGuire
| | +* Re: “Why do arrays start at 0?"Keith Thompson
| | |`- Re: “Why do arrays start at 0?"gah4
| | +* Re: “Why do arrays start at 0?"Thomas Koenig
| | |`- Re: “Why do arrays start at 0?"David Brown
| | `- Re: “Why do arrays start at 0?"Paavo Helde
| `* Re: “Why do arrays start at 0?"Fred. Zwarts
|  `- Re: “Why do arrays start at 0?"Thomas Koenig
+* Re: “Why do arrays start at 0?"Bonita Montero
|+- Re: “Why do arrays start at 0?"gah4
|`- Re: “Why do arrays start at 0?"Robin Vowels
`* Re: ???Why do arrays start at 0?"Juha Nieminen
 `- Re: ???Why do arrays start at 0?"gah4

Pages:123
Re: “Why do arrays start at 0?"

<xAZOK.851588$J0r9.702890@fx11.iad>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=2778&group=comp.lang.fortran#2778

  copy link   Newsgroups: comp.lang.fortran
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer01.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx11.iad.POSTED!not-for-mail
MIME-Version: 1.0
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.13; rv:102.0)
Gecko/20100101 Thunderbird/102.2.0
Subject: Re: “Why do arrays start at 0?"
Content-Language: en-US
Newsgroups: comp.lang.fortran
References: <tebblf$2gpm$1@dont-email.me>
<2ec469de-b871-4fe7-bafd-9ae32e40a434n@googlegroups.com>
<8a00a39d-e43d-42ee-8620-8090645fc43bn@googlegroups.com>
<22855686-fa84-4d0d-9790-b883cf1244cdn@googlegroups.com>
<teco73$ce2$1@newsreader4.netcologne.de>
<e9ab592e-6c95-4399-918c-3dd5f8a0c3b1n@googlegroups.com>
<tee4th$cqm$2@newsreader4.netcologne.de>
From: nospam@nowhere.org (Ron Shepard)
In-Reply-To: <tee4th$cqm$2@newsreader4.netcologne.de>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Lines: 31
Message-ID: <xAZOK.851588$J0r9.702890@fx11.iad>
X-Complaints-To: abuse@easynews.com
Organization: Forte - www.forteinc.com
X-Complaints-Info: Please be sure to forward a copy of ALL headers otherwise we will be unable to process your complaint properly.
Date: Mon, 29 Aug 2022 02:07:08 -0500
X-Received-Bytes: 2080
 by: Ron Shepard - Mon, 29 Aug 2022 07:07 UTC

On 8/27/22 5:13 PM, Thomas Koenig wrote:
> gah4 <gah4@u.washington.edu> schrieb:
>> On Saturday, August 27, 2022 at 2:30:15 AM UTC-7, Thomas Koenig wrote:
>>
>> (snip)
>>
>>>> Now for this case, you want a DO loop to start at zero, which Fortran 66
>>>> didn't allow.
>>
>>> Really? You mean that
>>
>>> DO 10 I=0,1
>>
>>> would not be allowed?
>>
>> Yes, not allowed.
>
> I have the Fortran 66 standard before me, and I find no such
> restriction in 7.1.2.8 (nor would it make sense at all).
>
> Which part of the standard are you referring to?

It is right there in that section in the paragraph that starts with (3).
The three integers m1, m2, and m3 must be greater than zero.

The only justification I can see for this is that they wanted to be able
to implement the loop logic with unsigned integers. Even then I don't
know why zero was not allowed.

$.02 -Ron Shepard

Re: “Why do arrays start at 0?"

<G5_OK.851589$J0r9.597646@fx11.iad>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=2779&group=comp.lang.fortran#2779

  copy link   Newsgroups: comp.lang.fortran
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer02.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx11.iad.POSTED!not-for-mail
MIME-Version: 1.0
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.13; rv:102.0)
Gecko/20100101 Thunderbird/102.2.0
Subject: Re: “Why do arrays start at 0?"
Content-Language: en-US
Newsgroups: comp.lang.fortran
References: <tebblf$2gpm$1@dont-email.me> <pvbOK.866404$ntj.801728@fx15.iad>
<fnumghl55e20valikh9oerct1bhk1g178r@4ax.com>
From: nospam@nowhere.org (Ron Shepard)
In-Reply-To: <fnumghl55e20valikh9oerct1bhk1g178r@4ax.com>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Lines: 29
Message-ID: <G5_OK.851589$J0r9.597646@fx11.iad>
X-Complaints-To: abuse@easynews.com
Organization: Forte - www.forteinc.com
X-Complaints-Info: Please be sure to forward a copy of ALL headers otherwise we will be unable to process your complaint properly.
Date: Mon, 29 Aug 2022 02:42:30 -0500
X-Received-Bytes: 2218
 by: Ron Shepard - Mon, 29 Aug 2022 07:42 UTC

On 8/28/22 9:28 AM, Charlie Roberts wrote:
[...]
> The authors of "Numerical Recipes" started out with F77 and so all the
> code in their first book has arrays starting at 1. When they brought
> out the C version, they resorted to just this trick!

If I remember correctly, the code in the chapters was written in Pascal,
and there was an appendix that had fortran code. Or maybe it was the
other way around? I don't remember what version of fortran they used, bu
the book was published before there were any f77 compilers available, so
I'm guessing that it was f66+extensions. Then they wrote the f77 version
a year or two later.

So the conventions they were mimicking in C were not really f77 (or even
Pascal), they were standard math conventions. C at that time was not
designed to do math. It did not even respect grouping of operands by
parentheses. This frustrating flaw in the C language would be corrected
some 19 years after the first language definition in the ANSI C version
of the language, c89.

When the NR authors did the pointer decrement hack, they took a lot of
criticism for writing nonstandard code. Then when they wrote the c++
version, they adjusted the math notation to fit the limitations of the
language.

$.02 -Ron Shepard

Re: “Why do arrays start at 0?"

<94e0c498-ad44-47b3-b869-e8142526aceen@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=2780&group=comp.lang.fortran#2780

  copy link   Newsgroups: comp.lang.fortran
X-Received: by 2002:ac8:5c95:0:b0:344:dde5:7d64 with SMTP id r21-20020ac85c95000000b00344dde57d64mr9228144qta.674.1661761830056;
Mon, 29 Aug 2022 01:30:30 -0700 (PDT)
X-Received: by 2002:a0d:c681:0:b0:33c:2e21:4756 with SMTP id
i123-20020a0dc681000000b0033c2e214756mr8779990ywd.467.1661761829867; Mon, 29
Aug 2022 01:30:29 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer03.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.fortran
Date: Mon, 29 Aug 2022 01:30:29 -0700 (PDT)
In-Reply-To: <xAZOK.851588$J0r9.702890@fx11.iad>
Injection-Info: google-groups.googlegroups.com; posting-host=202.67.103.232; posting-account=S_MdrwoAAAD7T2pxG2e393dk6y0tc0Le
NNTP-Posting-Host: 202.67.103.232
References: <tebblf$2gpm$1@dont-email.me> <2ec469de-b871-4fe7-bafd-9ae32e40a434n@googlegroups.com>
<8a00a39d-e43d-42ee-8620-8090645fc43bn@googlegroups.com> <22855686-fa84-4d0d-9790-b883cf1244cdn@googlegroups.com>
<teco73$ce2$1@newsreader4.netcologne.de> <e9ab592e-6c95-4399-918c-3dd5f8a0c3b1n@googlegroups.com>
<tee4th$cqm$2@newsreader4.netcologne.de> <xAZOK.851588$J0r9.702890@fx11.iad>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <94e0c498-ad44-47b3-b869-e8142526aceen@googlegroups.com>
Subject: Re: “Why do arrays start at 0?"
From: robin.vowels@gmail.com (Robin Vowels)
Injection-Date: Mon, 29 Aug 2022 08:30:30 +0000
Content-Type: text/plain; charset="UTF-8"
X-Received-Bytes: 2758
 by: Robin Vowels - Mon, 29 Aug 2022 08:30 UTC

On Monday, August 29, 2022 at 5:07:13 PM UTC+10, Ron Shepard wrote:
> On 8/27/22 5:13 PM, Thomas Koenig wrote:
> > gah4 <ga...@u.washington.edu> schrieb:
> >> On Saturday, August 27, 2022 at 2:30:15 AM UTC-7, Thomas Koenig wrote:
> >>
> >> (snip)
> >>
> >>>> Now for this case, you want a DO loop to start at zero, which Fortran 66
> >>>> didn't allow.
> >>
> >>> Really? You mean that
> >>
> >>> DO 10 I=0,1
> >>
> >>> would not be allowed?
> >>
> >> Yes, not allowed.
> >
> > I have the Fortran 66 standard before me, and I find no such
> > restriction in 7.1.2.8 (nor would it make sense at all).
> >
> > Which part of the standard are you referring to?
> It is right there in that section in the paragraph that starts with (3).
> The three integers m1, m2, and m3 must be greater than zero.
>
> The only justification I can see for this is that they wanted to be able
> to implement the loop logic with unsigned integers.
..
Definitely not.
The control variable at least would be an ordinary signed integer,
because that variable could be used in integer and/or real
expressions.
..
And if m2 and m3 are variables,, then for the same reason,
these would be ordinary signed integers.
..
> Even then I don't know why zero was not allowed.

Re: “Why do arrays start at 0?"

<57b86ace-8f93-4b04-8654-9d250d771a72n@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=2781&group=comp.lang.fortran#2781

  copy link   Newsgroups: comp.lang.fortran
X-Received: by 2002:a05:622a:1895:b0:344:f8dc:d070 with SMTP id v21-20020a05622a189500b00344f8dcd070mr9514906qtc.416.1661770123790;
Mon, 29 Aug 2022 03:48:43 -0700 (PDT)
X-Received: by 2002:a25:874d:0:b0:695:9b0d:abfe with SMTP id
e13-20020a25874d000000b006959b0dabfemr8036569ybn.88.1661770123602; Mon, 29
Aug 2022 03:48:43 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer03.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.fortran
Date: Mon, 29 Aug 2022 03:48:43 -0700 (PDT)
In-Reply-To: <xAZOK.851588$J0r9.702890@fx11.iad>
Injection-Info: google-groups.googlegroups.com; posting-host=2601:602:9700:4689:71e2:e748:49a2:9bbc;
posting-account=gLDX1AkAAAA26M5HM-O3sVMAXdxK9FPA
NNTP-Posting-Host: 2601:602:9700:4689:71e2:e748:49a2:9bbc
References: <tebblf$2gpm$1@dont-email.me> <2ec469de-b871-4fe7-bafd-9ae32e40a434n@googlegroups.com>
<8a00a39d-e43d-42ee-8620-8090645fc43bn@googlegroups.com> <22855686-fa84-4d0d-9790-b883cf1244cdn@googlegroups.com>
<teco73$ce2$1@newsreader4.netcologne.de> <e9ab592e-6c95-4399-918c-3dd5f8a0c3b1n@googlegroups.com>
<tee4th$cqm$2@newsreader4.netcologne.de> <xAZOK.851588$J0r9.702890@fx11.iad>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <57b86ace-8f93-4b04-8654-9d250d771a72n@googlegroups.com>
Subject: Re: “Why do arrays start at 0?"
From: gah4@u.washington.edu (gah4)
Injection-Date: Mon, 29 Aug 2022 10:48:43 +0000
Content-Type: text/plain; charset="UTF-8"
X-Received-Bytes: 2336
 by: gah4 - Mon, 29 Aug 2022 10:48 UTC

On Monday, August 29, 2022 at 12:07:13 AM UTC-7, Ron Shepard wrote:

(snip on DO loops)

> It is right there in that section in the paragraph that starts with (3).
> The three integers m1, m2, and m3 must be greater than zero.
> The only justification I can see for this is that they wanted to be able
> to implement the loop logic with unsigned integers. Even then I don't
> know why zero was not allowed.

There are a lot of restrictions in Fortran 66 that aren't at all obvious.

I thought this one went back to Fortran I on the 704, but don't see it there.

Some machines have special hardware registers for loops,
and might have restrictions not obvious today. In any case, the
restriction is there, and was enforced by some compilers for
constants, that otherwise didn't need to be restricted.

Re: ???Why do arrays start at 0?"

<tei759$19qc$1@gioia.aioe.org>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=2784&group=comp.lang.fortran#2784

  copy link   Newsgroups: comp.lang.fortran comp.lang.c++
Path: i2pn2.org!i2pn.org!aioe.org!NK0c7qMEn6mmBWqphs27pg.user.46.165.242.75.POSTED!not-for-mail
From: nospam@thanks.invalid (Juha Nieminen)
Newsgroups: comp.lang.fortran,comp.lang.c++
Subject: Re: ???Why do arrays start at 0?"
Date: Mon, 29 Aug 2022 11:15:56 -0000 (UTC)
Organization: Aioe.org NNTP Server
Message-ID: <tei759$19qc$1@gioia.aioe.org>
References: <tebblf$2gpm$1@dont-email.me>
Injection-Info: gioia.aioe.org; logging-data="42828"; posting-host="NK0c7qMEn6mmBWqphs27pg.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: tin/2.4.3-20181224 ("Glen Mhor") (UNIX) (Linux/5.10.103-grsec-kapsi (x86_64))
X-Notice: Filtered by postfilter v. 0.9.2
 by: Juha Nieminen - Mon, 29 Aug 2022 11:15 UTC

In comp.lang.c++ Lynn McGuire <lynnmcguire5@gmail.com> wrote:
> ???Why do arrays start at 0?"
> https://buttondown.email/hillelwayne/archive/why-do-arrays-start-at-0/
>
> "It's not the reason you think. No, it's not that reason either.???
>
> My Fortran starts at one. My C++ starts at zero. This has made my life
> hell.

I don't know if it's the *original* reason, but I would assume that at least
in C one of the main reasons is the principle of maximum efficiency.

In many processor architectures the concept of "array" exists, at least
when it comes to values of the register sizes (ie. usually 1-byte,
2-byte, 4-byte and 8-byte elements, the last one at least on 64-bit
architectures). Prominently the concept of an indexable array exists
in the x86 architecture. (I don't remember now if it also exists in
the ARM architecture, but I would guess so.)

Generally when a processor architecture supports the concept of an "array",
it does so by having instructions that take (at least) two registers as
the input or the output parameter: A base address, and an offset. The
memory location of the element is calculated by adding those two. (The
number of bytes that an offset of 1 jumps depends on the instruction,
and thus multi-byte elements are supported.)

Thus zero-indexing is extraordinarily natural in processor architectures:
The "index" is actually an offset. It's a value you add to the base
address in order to get to the location you want. Thus, the first element
is at index/offset 0.

Since that's the case, the most optimal way to handle low-level arrays is
to have 0-based indexing in the programming language as well. That way
you don't need to be subtracting 1 from the index every time an array is
accessed (or you don't need an extraneous unused element at the beginning
of the array, consuming memory for no reason).

Also, since C supports pointer arithmetic, many operations become simpler.
Such as getting the index of an element when what you have is a pointer to
it (and the pointer to the start of the array).

Re: “Why do arrays start at 0?"

<wI4PK.2$R_o7.1@fx33.iad>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=2787&group=comp.lang.fortran#2787

  copy link   Newsgroups: comp.lang.fortran
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer03.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx33.iad.POSTED!not-for-mail
MIME-Version: 1.0
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.13; rv:102.0)
Gecko/20100101 Thunderbird/102.2.0
Subject: Re: “Why do arrays start at 0?"
Content-Language: en-US
Newsgroups: comp.lang.fortran
References: <tebblf$2gpm$1@dont-email.me>
<2ec469de-b871-4fe7-bafd-9ae32e40a434n@googlegroups.com>
<8a00a39d-e43d-42ee-8620-8090645fc43bn@googlegroups.com>
<22855686-fa84-4d0d-9790-b883cf1244cdn@googlegroups.com>
<teco73$ce2$1@newsreader4.netcologne.de>
<e9ab592e-6c95-4399-918c-3dd5f8a0c3b1n@googlegroups.com>
<tee4th$cqm$2@newsreader4.netcologne.de> <xAZOK.851588$J0r9.702890@fx11.iad>
<94e0c498-ad44-47b3-b869-e8142526aceen@googlegroups.com>
From: nospam@nowhere.org (Ron Shepard)
In-Reply-To: <94e0c498-ad44-47b3-b869-e8142526aceen@googlegroups.com>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Lines: 30
Message-ID: <wI4PK.2$R_o7.1@fx33.iad>
X-Complaints-To: abuse@easynews.com
Organization: Forte - www.forteinc.com
X-Complaints-Info: Please be sure to forward a copy of ALL headers otherwise we will be unable to process your complaint properly.
Date: Mon, 29 Aug 2022 10:13:32 -0500
X-Received-Bytes: 2443
 by: Ron Shepard - Mon, 29 Aug 2022 15:13 UTC

On 8/29/22 3:30 AM, Robin Vowels wrote:
> On Monday, August 29, 2022 at 5:07:13 PM UTC+10, Ron Shepard wrote:
[...]
>> The only justification I can see for this is that they wanted to be able
>> to implement the loop logic with unsigned integers.
> .
> Definitely not.
> The control variable at least would be an ordinary signed integer,
> because that variable could be used in integer and/or real
> expressions.

Yes, the index variable and all three variables m1, m2, and m3 are
fortran integers. There was no unsigned integer type in fortran then. or
now for that matter, so these variables were all regular fortran signed
integers.

> And if m2 and m3 are variables,, then for the same reason,
> these would be ordinary signed integers.
> .
>> Even then I don't know why zero was not allowed.

Yes, see above. Fortran did not have unsigned integers, then or now. But
as I said before, the only reason I can imagine for having that
limitation in the language is that they wanted to allow the processor to
implement the loop control logic using unsigned integers in whatever
instruction set the compiled code was running.

$.02 -Ron Shepard

Re: “Why do arrays start at 0?"

<bad06ce5-df1c-40f1-9cb0-6af68b1e4131n@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=2789&group=comp.lang.fortran#2789

  copy link   Newsgroups: comp.lang.fortran
X-Received: by 2002:a05:620a:1a07:b0:6bc:3aa1:90fb with SMTP id bk7-20020a05620a1a0700b006bc3aa190fbmr9564964qkb.292.1661801400501;
Mon, 29 Aug 2022 12:30:00 -0700 (PDT)
X-Received: by 2002:a25:320b:0:b0:693:8371:4836 with SMTP id
y11-20020a25320b000000b0069383714836mr10047665yby.313.1661801400275; Mon, 29
Aug 2022 12:30:00 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer02.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.fortran
Date: Mon, 29 Aug 2022 12:30:00 -0700 (PDT)
In-Reply-To: <wI4PK.2$R_o7.1@fx33.iad>
Injection-Info: google-groups.googlegroups.com; posting-host=202.67.103.232; posting-account=S_MdrwoAAAD7T2pxG2e393dk6y0tc0Le
NNTP-Posting-Host: 202.67.103.232
References: <tebblf$2gpm$1@dont-email.me> <2ec469de-b871-4fe7-bafd-9ae32e40a434n@googlegroups.com>
<8a00a39d-e43d-42ee-8620-8090645fc43bn@googlegroups.com> <22855686-fa84-4d0d-9790-b883cf1244cdn@googlegroups.com>
<teco73$ce2$1@newsreader4.netcologne.de> <e9ab592e-6c95-4399-918c-3dd5f8a0c3b1n@googlegroups.com>
<tee4th$cqm$2@newsreader4.netcologne.de> <xAZOK.851588$J0r9.702890@fx11.iad>
<94e0c498-ad44-47b3-b869-e8142526aceen@googlegroups.com> <wI4PK.2$R_o7.1@fx33.iad>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <bad06ce5-df1c-40f1-9cb0-6af68b1e4131n@googlegroups.com>
Subject: Re: “Why do arrays start at 0?"
From: robin.vowels@gmail.com (Robin Vowels)
Injection-Date: Mon, 29 Aug 2022 19:30:00 +0000
Content-Type: text/plain; charset="UTF-8"
X-Received-Bytes: 3102
 by: Robin Vowels - Mon, 29 Aug 2022 19:30 UTC

On Tuesday, August 30, 2022 at 1:13:37 AM UTC+10, Ron Shepard wrote:
> On 8/29/22 3:30 AM, Robin Vowels wrote:
> > On Monday, August 29, 2022 at 5:07:13 PM UTC+10, Ron Shepard wrote:
> [...]
> >> The only justification I can see for this is that they wanted to be able
> >> to implement the loop logic with unsigned integers.
> > .
> > Definitely not.
> > The control variable at least would be an ordinary signed integer,
> > because that variable could be used in integer and/or real
> > expressions.
> Yes, the index variable and all three variables m1, m2, and m3 are
> fortran integers. There was no unsigned integer type in fortran then. or
> now for that matter, so these variables were all regular fortran signed
> integers.
> > And if m2 and m3 are variables,, then for the same reason,
> > these would be ordinary signed integers.
> > .
> >> Even then I don't know why zero was not allowed..

> Yes, see above. Fortran did not have unsigned integers, then or now. But
> as I said before, the only reason I can imagine for having that
> limitation in the language is that they wanted to allow the processor to
> implement the loop control logic using unsigned integers in whatever
> instruction set the compiled code was running.
..
Some hardware used signed-magnitude form.
The arithmetic for incrementing the control variable
would have been implemented using whatever hardware was normally
used for integer arithmetic anywhere in the machine.
..
Similarly for comparing the loop control variable with m2.

Re: ???Why do arrays start at 0?"

<317d57ec-0fbe-476a-98b9-a33f4c369b1bn@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=2797&group=comp.lang.fortran#2797

  copy link   Newsgroups: comp.lang.fortran
X-Received: by 2002:a05:620a:178c:b0:6bb:b3a8:88f9 with SMTP id ay12-20020a05620a178c00b006bbb3a888f9mr10901898qkb.759.1661839140543;
Mon, 29 Aug 2022 22:59:00 -0700 (PDT)
X-Received: by 2002:a25:bdd4:0:b0:696:4dbd:dcc9 with SMTP id
g20-20020a25bdd4000000b006964dbddcc9mr10937196ybk.392.1661839140218; Mon, 29
Aug 2022 22:59:00 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer03.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.fortran
Date: Mon, 29 Aug 2022 22:59:00 -0700 (PDT)
In-Reply-To: <tei759$19qc$1@gioia.aioe.org>
Injection-Info: google-groups.googlegroups.com; posting-host=2601:602:9700:4689:9436:1cc2:ea0:7fd3;
posting-account=gLDX1AkAAAA26M5HM-O3sVMAXdxK9FPA
NNTP-Posting-Host: 2601:602:9700:4689:9436:1cc2:ea0:7fd3
References: <tebblf$2gpm$1@dont-email.me> <tei759$19qc$1@gioia.aioe.org>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <317d57ec-0fbe-476a-98b9-a33f4c369b1bn@googlegroups.com>
Subject: Re: ???Why do arrays start at 0?"
From: gah4@u.washington.edu (gah4)
Injection-Date: Tue, 30 Aug 2022 05:59:00 +0000
Content-Type: text/plain; charset="UTF-8"
X-Received-Bytes: 5093
 by: gah4 - Tue, 30 Aug 2022 05:59 UTC

On Monday, August 29, 2022 at 4:16:00 AM UTC-7, Juha Nieminen wrote:

(snip)

> I don't know if it's the *original* reason, but I would assume that at least
> in C one of the main reasons is the principle of maximum efficiency.
> In many processor architectures the concept of "array" exists, at least
> when it comes to values of the register sizes (ie. usually 1-byte,
> 2-byte, 4-byte and 8-byte elements, the last one at least on 64-bit
> architectures). Prominently the concept of an indexable array exists
> in the x86 architecture. (I don't remember now if it also exists in
> the ARM architecture, but I would guess so.)
BCPL, a predecessor of C, was written on a word addressable
machine. Pointer arithmetic was integer arithmetic. It was with
C that variables could be larger than the addressable unit,
and that pointers (addresses) incremented and decremented
in appropriate sized units.

In any case, early C (and B and BCPL) programmers were likely
also assembly programmers, and would have been used
to 0 origin indexing.

> Generally when a processor architecture supports the concept of an "array",
> it does so by having instructions that take (at least) two registers as
> the input or the output parameter: A base address, and an offset. The
> memory location of the element is calculated by adding those two. (The
> number of bytes that an offset of 1 jumps depends on the instruction,
> and thus multi-byte elements are supported.)

For many machines, you have to multiply by the element size,
but yes some do it for you. C pointer arithmetic is defined in terms
of the size of the pointed-to object, and array indexing is defined
in terms of pointer arithmetic.
> Thus zero-indexing is extraordinarily natural in processor architectures:
> The "index" is actually an offset. It's a value you add to the base
> address in order to get to the location you want. Thus, the first element
> is at index/offset 0.
> Since that's the case, the most optimal way to handle low-level arrays is
> to have 0-based indexing in the programming language as well. That way
> you don't need to be subtracting 1 from the index every time an array is
> accessed (or you don't need an extraneous unused element at the beginning
> of the array, consuming memory for no reason).

In the case of Fortran, starting with static arrays, the compiler can subtract
before generating the address constant, such that the subtract is done
at compile time. No run-time cost.

For allocatable arrays, it can adjust the offset once, and use that.

For automatic variables on the stack, the stack pointer offset is
computed once.

The way C pointers are defined, that would not be quite as
easy to do. Or, C pointers are defined the way they are to make it easier.

Fortran was originally Formula Translation, and mathematicians did,
and still do, use 1 based indexing for matrices and vectors.

> Also, since C supports pointer arithmetic, many operations become simpler.
> Such as getting the index of an element when what you have is a pointer to
> it (and the pointer to the start of the array).

Note that it gets more interesting for Fortran. When you pass an array
as an argument to a subroutine, it loses the original origin.
(Well, most of the time. Remembering when it does and doesn't is
probably harder than figuring out 0 vs.1 origin.)

One that C programmers like to do, and I suspect was faster on
many early machines, is index through arrays with a pointer to an array,
indexing it as it goes. That means no subscript calculation in the loop.
Many early C processors didn't have multiply, or had slow multiply.

However, one of the favorite optimizations for Fortran compilers
is strength reduction, converting multiply inside a loop into addition
as the loop increments. The result is pretty much the same.

Re: “Why do arrays start at 0?"

<telgoc$74h$1@newsreader4.netcologne.de>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=2805&group=comp.lang.fortran#2805

  copy link   Newsgroups: comp.lang.fortran
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!newsreader4.netcologne.de!news.netcologne.de!.POSTED.2001-4dd7-4e56-0-7285-c2ff-fe6c-992d.ipv6dyn.netcologne.de!not-for-mail
From: tkoenig@netcologne.de (Thomas Koenig)
Newsgroups: comp.lang.fortran
Subject: Re: “Why do arrays start at 0?"
Date: Tue, 30 Aug 2022 17:18:04 -0000 (UTC)
Organization: news.netcologne.de
Distribution: world
Message-ID: <telgoc$74h$1@newsreader4.netcologne.de>
References: <tebblf$2gpm$1@dont-email.me> <pvbOK.866404$ntj.801728@fx15.iad>
<fnumghl55e20valikh9oerct1bhk1g178r@4ax.com>
<G5_OK.851589$J0r9.597646@fx11.iad>
Injection-Date: Tue, 30 Aug 2022 17:18:04 -0000 (UTC)
Injection-Info: newsreader4.netcologne.de; posting-host="2001-4dd7-4e56-0-7285-c2ff-fe6c-992d.ipv6dyn.netcologne.de:2001:4dd7:4e56:0:7285:c2ff:fe6c:992d";
logging-data="7313"; mail-complaints-to="abuse@netcologne.de"
User-Agent: slrn/1.0.3 (Linux)
 by: Thomas Koenig - Tue, 30 Aug 2022 17:18 UTC

Ron Shepard <nospam@nowhere.org> schrieb:
> On 8/28/22 9:28 AM, Charlie Roberts wrote:
> [...]
>> The authors of "Numerical Recipes" started out with F77 and so all the
>> code in their first book has arrays starting at 1. When they brought
>> out the C version, they resorted to just this trick!
>
> If I remember correctly, the code in the chapters was written in Pascal,
> and there was an appendix that had fortran code. Or maybe it was the
> other way around?

The first edition was released in 1986, for Fortran, see the
Wikipedia article.

> I don't remember what version of fortran they used, bu
> the book was published before there were any f77 compilers available,

This is not the case. I have a version of a manual for VS Fortran,
from February 1981, which describes a Fortran 77 compiler.

> so
> I'm guessing that it was f66+extensions. Then they wrote the f77 version
> a year or two later.

I have the first edition, it is definitely Fortran 77.

Re: “Why do arrays start at 0?"

<c414d891-4748-445e-a991-ebaa0b63ea30n@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=2808&group=comp.lang.fortran#2808

  copy link   Newsgroups: comp.lang.fortran
X-Received: by 2002:a05:620a:290d:b0:6b5:cecc:1cab with SMTP id m13-20020a05620a290d00b006b5cecc1cabmr12736684qkp.465.1661886911983;
Tue, 30 Aug 2022 12:15:11 -0700 (PDT)
X-Received: by 2002:a25:874d:0:b0:695:9b0d:abfe with SMTP id
e13-20020a25874d000000b006959b0dabfemr13042447ybn.88.1661886911740; Tue, 30
Aug 2022 12:15:11 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer01.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.fortran
Date: Tue, 30 Aug 2022 12:15:11 -0700 (PDT)
In-Reply-To: <telgoc$74h$1@newsreader4.netcologne.de>
Injection-Info: google-groups.googlegroups.com; posting-host=2601:602:9700:4689:9436:1cc2:ea0:7fd3;
posting-account=gLDX1AkAAAA26M5HM-O3sVMAXdxK9FPA
NNTP-Posting-Host: 2601:602:9700:4689:9436:1cc2:ea0:7fd3
References: <tebblf$2gpm$1@dont-email.me> <pvbOK.866404$ntj.801728@fx15.iad>
<fnumghl55e20valikh9oerct1bhk1g178r@4ax.com> <G5_OK.851589$J0r9.597646@fx11.iad>
<telgoc$74h$1@newsreader4.netcologne.de>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <c414d891-4748-445e-a991-ebaa0b63ea30n@googlegroups.com>
Subject: Re: “Why do arrays start at 0?"
From: gah4@u.washington.edu (gah4)
Injection-Date: Tue, 30 Aug 2022 19:15:11 +0000
Content-Type: text/plain; charset="UTF-8"
X-Received-Bytes: 1752
 by: gah4 - Tue, 30 Aug 2022 19:15 UTC

On Tuesday, August 30, 2022 at 10:18:08 AM UTC-7, Thomas Koenig wrote:

(snip)

> This is not the case. I have a version of a manual for VS Fortran,
> from February 1981, which describes a Fortran 77 compiler.

WATFIV had most of the Fortran 77 features in 1973, but we
didn't know it at the time.

As well as I know, it was testing them out before the standard
was done. Much more fun at the time, though, than Fortran IV.

Pages:123
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor