Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.fortran > #73508 > unrolled thread

“Why do arrays start at 0?"

Started byLynn McGuire <lynnmcguire5@gmail.com>
First post2022-08-26 15:49 -0500
Last post2022-08-29 22:59 -0700
Articles 20 on this page of 60 — 20 participants

Back to article view | Back to comp.lang.fortran


Contents

  “Why do arrays start at 0?" Lynn McGuire <lynnmcguire5@gmail.com> - 2022-08-26 15:49 -0500
    Re: “Why do arrays start at 0?" Gary Scott <garylscott@sbcglobal.net> - 2022-08-26 16:56 -0500
      Re: “Why do arrays start at 0?" Mr Flibble <flibble@reddwarf.jmc.corp> - 2022-08-27 00:46 +0100
        Re: “Why do arrays start at 0?" d thiebaud <thiebauddick2@aol.com> - 2022-08-26 22:29 -0400
          Re: “Why do arrays start at 0?" gah4 <gah4@u.washington.edu> - 2022-08-26 19:34 -0700
          Re: “Why do arrays start at 0?" Robin Vowels <robin.vowels@gmail.com> - 2022-08-26 20:34 -0700
          Re: “Why do arrays start at 0?" Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2022-08-26 22:05 -0700
            Re: “Why do arrays start at 0?" Mr Flibble <flibble@reddwarf.jmc.corp> - 2022-08-27 12:06 +0100
      Re: “Why do arrays start at 0?" gah4 <gah4@u.washington.edu> - 2022-08-26 18:24 -0700
      Re: Re: “Why do arrays start at 0?" scott@slp53.sl.home (Scott Lurndal) - 2022-08-27 14:28 +0000
      Re: �Why do arrays start at 0?" Charlie Roberts <croberts@gmail.com> - 2022-08-28 10:25 -0400
    Re: “Why do arrays start at 0?" Louis Krupp <lkrupp@invalid.pssw.com.invalid> - 2022-08-26 16:08 -0600
      Re: �Why do arrays start at 0?" Charlie Roberts <croberts@gmail.com> - 2022-08-28 10:28 -0400
        Re: “Why do arrays start at 0?" Thomas Koenig <tkoenig@netcologne.de> - 2022-08-28 16:30 +0000
        Re: “Why do arrays start at 0?" Ron Shepard <nospam@nowhere.org> - 2022-08-29 02:42 -0500
          Re: “Why do arrays start at 0?" Thomas Koenig <tkoenig@netcologne.de> - 2022-08-30 17:18 +0000
            Re: “Why do arrays start at 0?" gah4 <gah4@u.washington.edu> - 2022-08-30 12:15 -0700
    Re: “Why do arrays start at 0?" Mr Flibble <flibble@reddwarf.jmc.corp> - 2022-08-27 00:44 +0100
    Re: “Why do arrays start at 0?" Robin Vowels <robin.vowels@gmail.com> - 2022-08-26 20:31 -0700
      Re: “Why do arrays start at 0?" "fiz...@gmail.com" <fiziqs@gmail.com> - 2022-08-27 01:48 -0700
        Re: “Why do arrays start at 0?" gah4 <gah4@u.washington.edu> - 2022-08-27 02:17 -0700
          Re: “Why do arrays start at 0?" Thomas Koenig <tkoenig@netcologne.de> - 2022-08-27 09:30 +0000
            Re: “Why do arrays start at 0?" gah4 <gah4@u.washington.edu> - 2022-08-27 10:01 -0700
              Re: “Why do arrays start at 0?" Thomas Koenig <tkoenig@netcologne.de> - 2022-08-27 22:13 +0000
                Re: “Why do arrays start at 0?" gah4 <gah4@u.washington.edu> - 2022-08-27 22:26 -0700
                  Re: “Why do arrays start at 0?" Thomas Koenig <tkoenig@netcologne.de> - 2022-08-28 06:59 +0000
                  Re: “Why do arrays start at 0?" Lynn McGuire <lynnmcguire5@gmail.com> - 2022-08-28 13:42 -0500
                    Re: “Why do arrays start at 0?" Thomas Koenig <tkoenig@netcologne.de> - 2022-08-28 20:17 +0000
                      Re: “Why do arrays start at 0?" gah4 <gah4@u.washington.edu> - 2022-08-28 14:08 -0700
                    Re: “Why do arrays start at 0?" gah4 <gah4@u.washington.edu> - 2022-08-28 14:05 -0700
                      Re: “Why do arrays start at 0?" Robin Vowels <robin.vowels@gmail.com> - 2022-08-28 21:54 -0700
                    Re: “Why do arrays start at 0?" Robin Vowels <robin.vowels@gmail.com> - 2022-08-28 21:53 -0700
                Re: “Why do arrays start at 0?" Ron Shepard <nospam@nowhere.org> - 2022-08-29 02:07 -0500
                  Re: “Why do arrays start at 0?" Robin Vowels <robin.vowels@gmail.com> - 2022-08-29 01:30 -0700
                    Re: “Why do arrays start at 0?" Ron Shepard <nospam@nowhere.org> - 2022-08-29 10:13 -0500
                      Re: “Why do arrays start at 0?" Robin Vowels <robin.vowels@gmail.com> - 2022-08-29 12:30 -0700
                  Re: “Why do arrays start at 0?" gah4 <gah4@u.washington.edu> - 2022-08-29 03:48 -0700
        Re: “Why do arrays start at 0?" Robin Vowels <robin.vowels@gmail.com> - 2022-08-27 05:16 -0700
    Re: “Why do arrays start at 0?" Thomas Koenig <tkoenig@netcologne.de> - 2022-08-27 05:47 +0000
      Re: “Why do arrays start at 0?" d thiebaud <thiebauddick2@aol.com> - 2022-08-27 15:19 -0400
        Re: “Why do arrays start at 0?" FortranFan <parekhvs@gmail.com> - 2022-08-27 12:45 -0700
        Re: “Why do arrays start at 0?" Thomas Koenig <tkoenig@netcologne.de> - 2022-08-27 22:22 +0000
    Re: “Why do arrays start at 0?" "Fred. Zwarts" <F.Zwarts@KVI.nl> - 2022-08-27 21:26 +0200
      Re: “Why do arrays start at 0?" Lynn McGuire <lynnmcguire5@gmail.com> - 2022-08-27 15:01 -0500
        Re: “Why do arrays start at 0?" Thomas Koenig <tkoenig@netcologne.de> - 2022-08-27 22:24 +0000
          Re: “Why do arrays start at 0?" John <urbanjost@comcast.net> - 2022-08-27 19:34 -0700
            Re: “Why do arrays start at 0?" Robin Vowels <robin.vowels@gmail.com> - 2022-08-28 01:50 -0700
          Re: “Why do arrays start at 0?" Lynn McGuire <lynnmcguire5@gmail.com> - 2022-08-27 22:40 -0500
            Re: “Why do arrays start at 0?" Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2022-08-27 22:07 -0700
              Re: “Why do arrays start at 0?" gah4 <gah4@u.washington.edu> - 2022-08-27 23:04 -0700
            Re: “Why do arrays start at 0?" Thomas Koenig <tkoenig@netcologne.de> - 2022-08-28 07:50 +0000
              Re: “Why do arrays start at 0?" David Brown <david.brown@hesbynett.no> - 2022-08-28 11:52 +0200
            Re: “Why do arrays start at 0?" Paavo Helde <eesnimi@osa.pri.ee> - 2022-08-28 19:43 +0300
        Re: “Why do arrays start at 0?" "Fred. Zwarts" <F.Zwarts@KVI.nl> - 2022-08-28 10:01 +0200
          Re: “Why do arrays start at 0?" Thomas Koenig <tkoenig@netcologne.de> - 2022-08-28 08:14 +0000
    Re: “Why do arrays start at 0?" Bonita Montero <Bonita.Montero@gmail.com> - 2022-08-28 11:07 +0200
      Re: “Why do arrays start at 0?" gah4 <gah4@u.washington.edu> - 2022-08-28 02:55 -0700
      Re: “Why do arrays start at 0?" Robin Vowels <robin.vowels@gmail.com> - 2022-08-28 05:47 -0700
    Re: ???Why do arrays start at 0?" Juha Nieminen <nospam@thanks.invalid> - 2022-08-29 11:15 +0000
      Re: ???Why do arrays start at 0?" gah4 <gah4@u.washington.edu> - 2022-08-29 22:59 -0700

Page 2 of 3 — ← Prev page 1 [2] 3  Next page →


#73521

Fromgah4 <gah4@u.washington.edu>
Date2022-08-27 02:17 -0700
Message-ID<22855686-fa84-4d0d-9790-b883cf1244cdn@googlegroups.com>
In reply to#73520
On Saturday, August 27, 2022 at 1:48:15 AM UTC-7, fiz...@gmail.com wrote:
> On Saturday, August 27, 2022 at 5:31:37 AM UTC+2, Robin Vowels wrote: 
> > On Saturday, August 27, 2022 at 6:49:55 AM UTC+10, Lynn McGuire wrote: 
> > FORTRAN followed centuries-old mathematical convention.
> Nope. Just as the linked article mentions, in Mathematics, starting an index
> from 0 or 1 are both often used, e.g., for elements of sequences and series, 
> 0 seems to be most often used, for vector and matrix indices, 1.

Yes, so array indexing is 1.  Series sums start at zero, but are not indexed.

> If a convergence of a sequence is considered, you often don't care about 
>"early" elements, so, if that yields a simple formula, you start from any
> number convenient.

Now for this case, you want a DO loop to start at zero, which Fortran 66
didn't allow.  But you normally sum inside the loop, not store element
in an array. 

> In Physics, you often start vector and matrix indices with 0 if the zeroth
> component is in some sense distinguished (e.g., in relativistic theories,
> distinguishing the time-like coordinate from the 3 space-like ones).
 
Yes, four-vectors. 

[toc] | [prev] | [next] | [standalone]


#73522

FromThomas Koenig <tkoenig@netcologne.de>
Date2022-08-27 09:30 +0000
Message-ID<teco73$ce2$1@newsreader4.netcologne.de>
In reply to#73521
gah4 <gah4@u.washington.edu> schrieb:
> On Saturday, August 27, 2022 at 1:48:15 AM UTC-7, fiz...@gmail.com wrote:
>> On Saturday, August 27, 2022 at 5:31:37 AM UTC+2, Robin Vowels wrote: 
>> > On Saturday, August 27, 2022 at 6:49:55 AM UTC+10, Lynn McGuire wrote: 
>> > FORTRAN followed centuries-old mathematical convention.
>> Nope. Just as the linked article mentions, in Mathematics, starting an index
>> from 0 or 1 are both often used, e.g., for elements of sequences and series, 
>> 0 seems to be most often used, for vector and matrix indices, 1.
>
> Yes, so array indexing is 1.  Series sums start at zero, but are not indexed.
>
>> If a convergence of a sequence is considered, you often don't care about 
>>"early" elements, so, if that yields a simple formula, you start from any
>> number convenient.
>
> 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?

You probably meant zero-trip loops which were undefined.

[toc] | [prev] | [next] | [standalone]


#73526

Fromgah4 <gah4@u.washington.edu>
Date2022-08-27 10:01 -0700
Message-ID<e9ab592e-6c95-4399-918c-3dd5f8a0c3b1n@googlegroups.com>
In reply to#73522
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.  And the IBM compilers wouldn't compile them
with a constant.  BXLE works fine with variables, though.
That was another change in Fortran 77.

> You probably meant zero-trip loops which were undefined.

And yes, even though the standard said undefined, many compilers
implemented the one-trip minimum, with the test at the end.
And so many believed that was required.


[toc] | [prev] | [next] | [standalone]


#73531

FromThomas Koenig <tkoenig@netcologne.de>
Date2022-08-27 22:13 +0000
Message-ID<tee4th$cqm$2@newsreader4.netcologne.de>
In reply to#73526
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?

[toc] | [prev] | [next] | [standalone]


#73537

Fromgah4 <gah4@u.washington.edu>
Date2022-08-27 22:26 -0700
Message-ID<993d8e78-7cfc-4768-a735-35aff3b5a911n@googlegroups.com>
In reply to#73531
On Saturday, August 27, 2022 at 3:13:09 PM UTC-7, 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)
> >> 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?

Yes 7.1.2.8.  

"At time of execution of the DO statement, m1, m2, and m3 must be greater than zero."

[toc] | [prev] | [next] | [standalone]


#73539

FromThomas Koenig <tkoenig@netcologne.de>
Date2022-08-28 06:59 +0000
Message-ID<tef3o7$vrr$1@newsreader4.netcologne.de>
In reply to#73537
gah4 <gah4@u.washington.edu> schrieb:
> On Saturday, August 27, 2022 at 3:13:09 PM UTC-7, 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)
>> >> 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?
>
> Yes 7.1.2.8.  
>
> "At time of execution of the DO statement, m1, m2, and m3 must be greater than zero."

OK, I missed that one.

Big hole, luckily rectified in subsequent versions.

[toc] | [prev] | [next] | [standalone]


#73552

FromLynn McGuire <lynnmcguire5@gmail.com>
Date2022-08-28 13:42 -0500
Message-ID<tegcug$tiu$1@gioia.aioe.org>
In reply to#73537
On 8/28/2022 12:26 AM, gah4 wrote:
> On Saturday, August 27, 2022 at 3:13:09 PM UTC-7, 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)
>>>> 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?
> 
> Yes 7.1.2.8.
> 
> "At time of execution of the DO statement, m1, m2, and m3 must be greater than zero."

What ?  Our code has negative indexes dating back to F66 days.  I am 
assuming that this is:

DO 10 I = ncp, 1, -1

Lynn

[toc] | [prev] | [next] | [standalone]


#73553

FromThomas Koenig <tkoenig@netcologne.de>
Date2022-08-28 20:17 +0000
Message-ID<tegigf$vfn$1@newsreader4.netcologne.de>
In reply to#73552
Lynn McGuire <lynnmcguire5@gmail.com> schrieb:
> On 8/28/2022 12:26 AM, gah4 wrote:
>> On Saturday, August 27, 2022 at 3:13:09 PM UTC-7, 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)
>>>>> 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?
>> 
>> Yes 7.1.2.8.
>> 
>> "At time of execution of the DO statement, m1, m2, and m3 must be greater than zero."
>
> What ?  Our code has negative indexes dating back to F66 days.  I am 
> assuming that this is:
>
> DO 10 I = ncp, 1, -1

Hm.  Seems like this was carried over from the very first FORTRAN.
The 1956 Programmer's Reference Manual restricted them to unsigned
fixed point constants.

Looking at the Fortran IV language at
http://www.bitsavers.org/pdf/ibm/360/fortran/C28-6515-6_FORTRAN_IV_Language_1966.pdf
we have the same restriction.

So, seems like an extension at the time (a very useful one, too).

[toc] | [prev] | [next] | [standalone]


#73555

Fromgah4 <gah4@u.washington.edu>
Date2022-08-28 14:08 -0700
Message-ID<a46aaa28-82bf-44ca-a2e4-223f27438cd5n@googlegroups.com>
In reply to#73553
On Sunday, August 28, 2022 at 1:17:22 PM UTC-7, Thomas Koenig wrote:

(snip)

> Hm. Seems like this was carried over from the very first FORTRAN. 
> The 1956 Programmer's Reference Manual restricted them to unsigned 
> fixed point constants. 
 
> Looking at the Fortran IV language at 
> http://www.bitsavers.org/pdf/ibm/360/fortran/C28-6515-6_FORTRAN_IV_Language_1966.pdf 
> we have the same restriction. 
 
> So, seems like an extension at the time (a very useful one, too).

It is not so hard to do with a constant, but IBM didn't do that.  It is harder
with a variable, as the test direction depends on the sign. 

IBM S/360 compilers use BXLE, Branch on indeX Less than or Equal, to 
increment and test, at the end of the loop. 

IBM was always good at marking their extensions with gray shading in the
manuals.  

[toc] | [prev] | [next] | [standalone]


#73554

Fromgah4 <gah4@u.washington.edu>
Date2022-08-28 14:05 -0700
Message-ID<a8f49c04-8100-44af-87ff-d52530542f49n@googlegroups.com>
In reply to#73552
On Sunday, August 28, 2022 at 11:42:28 AM UTC-7, Lynn McGuire wrote:
> On 8/28/2022 12:26 AM, gah4 wrote: 

(snip, I wrote)

> > "At time of execution of the DO statement, m1, m2, and m3 must be greater than zero."

> What ? Our code has negative indexes dating back to F66 days. I am 
> assuming that this is: 
 
> DO 10 I = ncp, 1, -1 
 
Many systems had extensions to Fortran 66, and that might not have been unusual.

Those competing with IBM needed a way to make there systems look better,
and such extensions were one way to do it.  DEC had a lot of extensions like that.

On the other hand, IBM was careful with theirs. The had some big extensions
where there was no way around them.  END= on READ was very useful!

But DO look changes that were easy to make with a temporary variable
did not get an extension.  Making m3 negative means that the test 
has to be inverted.  IBM Fortran IV compilers don't change the test.

As note, though, IBM Fortran IV compilers will also disallow:

   DO 10 I=0,9

though if you use a variable set to 0, it works just fine.
(Unless the optimizer figures it out, and disallows it.)

Similarly, 

DO 10 I = ncp, 1, -1 

won't compile.  If you use a variable set to -1, it will
loop until the variable wraps to a large value.

[toc] | [prev] | [next] | [standalone]


#73557

FromRobin Vowels <robin.vowels@gmail.com>
Date2022-08-28 21:54 -0700
Message-ID<7f4d38e8-3adb-42c5-9677-2ea53a97ea59n@googlegroups.com>
In reply to#73554
On Monday, August 29, 2022 at 7:05:08 AM UTC+10, gah4 wrote:
> On Sunday, August 28, 2022 at 11:42:28 AM UTC-7, Lynn McGuire wrote: 
> > On 8/28/2022 12:26 AM, gah4 wrote:
> (snip, I wrote)
> > > "At time of execution of the DO statement, m1, m2, and m3 must be greater than zero." 
> 
> > What ? Our code has negative indexes dating back to F66 days. I am 
> > assuming that this is: 
> 
> > DO 10 I = ncp, 1, -1
> Many systems had extensions to Fortran 66, and that might not have been unusual. 
> 
> Those competing with IBM needed a way to make there systems look better, 
> and such extensions were one way to do it. DEC had a lot of extensions like that. 
> 
> On the other hand, IBM was careful with theirs. The had some big extensions 
> where there was no way around them. END= on READ was very useful! 
> 
> But DO look changes that were easy to make with a temporary variable 
> did not get an extension. Making m3 negative means that the test 
> has to be inverted. IBM Fortran IV compilers don't change the test. 
> 
> As note, though, IBM Fortran IV compilers will also disallow: 
> 
> DO 10 I=0,9 
> 
> though if you use a variable set to 0, it works just fine. 
> (Unless the optimizer figures it out, and disallows it.) 
> 
> Similarly,
> DO 10 I = ncp, 1, -1
> won't compile. If you use a variable set to -1, it will 
> loop until the variable wraps to a large value.
.
You might have to wait a long time for that to happen.

[toc] | [prev] | [next] | [standalone]


#73556

FromRobin Vowels <robin.vowels@gmail.com>
Date2022-08-28 21:53 -0700
Message-ID<154b6b23-0626-4e56-8445-442d1add77een@googlegroups.com>
In reply to#73552
On Monday, August 29, 2022 at 4:42:28 AM UTC+10, Lynn McGuire wrote:
> On 8/28/2022 12:26 AM, gah4 wrote: 
> > On Saturday, August 27, 2022 at 3:13:09 PM UTC-7, 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) 
> >>>> 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? 
> > 
> > Yes 7.1.2.8. 
> > 
> > "At time of execution of the DO statement, m1, m2, and m3 must be greater than zero."
> What ? Our code has negative indexes dating back to F66 days. I am 
> assuming that this is: 
> 
> DO 10 I = ncp, 1, -1 
.
All of these were valid in PL/I from the beginning (1966) --
negative increments, initial values starting at zero or even negative.
.
As well, a PL/I loop could be executed 0 times (inlike FORTRAN
which, at that time, insisted in executing a loop at least once,
even if the initial value was greater than the final value).

[toc] | [prev] | [next] | [standalone]


#73558

FromRon Shepard <nospam@nowhere.org>
Date2022-08-29 02:07 -0500
Message-ID<xAZOK.851588$J0r9.702890@fx11.iad>
In reply to#73531
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

[toc] | [prev] | [next] | [standalone]


#73560

FromRobin Vowels <robin.vowels@gmail.com>
Date2022-08-29 01:30 -0700
Message-ID<94e0c498-ad44-47b3-b869-e8142526aceen@googlegroups.com>
In reply to#73558
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.

[toc] | [prev] | [next] | [standalone]


#73567

FromRon Shepard <nospam@nowhere.org>
Date2022-08-29 10:13 -0500
Message-ID<wI4PK.2$R_o7.1@fx33.iad>
In reply to#73560
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

[toc] | [prev] | [next] | [standalone]


#73569

FromRobin Vowels <robin.vowels@gmail.com>
Date2022-08-29 12:30 -0700
Message-ID<bad06ce5-df1c-40f1-9cb0-6af68b1e4131n@googlegroups.com>
In reply to#73567
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.

[toc] | [prev] | [next] | [standalone]


#73561

Fromgah4 <gah4@u.washington.edu>
Date2022-08-29 03:48 -0700
Message-ID<57b86ace-8f93-4b04-8654-9d250d771a72n@googlegroups.com>
In reply to#73558
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.



[toc] | [prev] | [next] | [standalone]


#73524

FromRobin Vowels <robin.vowels@gmail.com>
Date2022-08-27 05:16 -0700
Message-ID<7db2d152-56f3-446c-9680-7208781aebe2n@googlegroups.com>
In reply to#73520
On Saturday, August 27, 2022 at 6:48:15 PM UTC+10, fiz...@gmail.com wrote:
> On Saturday, August 27, 2022 at 5:31:37 AM UTC+2, Robin Vowels wrote: 
> > On Saturday, August 27, 2022 at 6:49:55 AM UTC+10, Lynn McGuire wrote: 
> > FORTRAN followed centuries-old mathematical convention.
> Nope. Just as the linked article mentions, in Mathematics, starting an index from 0 or 1 are both often used, e.g., for elements of sequences and series, 0 seems to be most often used,
.
That's irrrelevnt to the OP's question.
.
 for vector and matrix indices, 1.

That's what I said.
It's an old tradition.

> If a convergence of a sequence is considered, you often don't care about "early" elements, so, if that yields a simple formula, you start from any number convenient. In Physics, you often start vector and matrix indices with 0
.
Really?  See above.
.
> if the zeroth component is in some sense distinguished (e.g., in relativistic theories, distinguishing the time-like coordinate from the 3 space-like ones).
.
> > FORTRAN started at 1 for subscripts.

[toc] | [prev] | [next] | [standalone]


#73519

FromThomas Koenig <tkoenig@netcologne.de>
Date2022-08-27 05:47 +0000
Message-ID<tecb60$5sh$1@newsreader4.netcologne.de>
In reply to#73508
Lynn McGuire <lynnmcguire5@gmail.com> schrieb:
> “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.

If you want to declare your Fortran arrays to start at zero, just
declare them with a lower bound of zero, like

  real, dimension(0:n-1) :: a

[toc] | [prev] | [next] | [standalone]


#73527

Fromd thiebaud <thiebauddick2@aol.com>
Date2022-08-27 15:19 -0400
Message-ID<tedqnk$1414$1@gioia.aioe.org>
In reply to#73519
On 8/27/22 01:47, Thomas Koenig wrote:
> Lynn McGuire <lynnmcguire5@gmail.com> schrieb:
>> “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.
> 
> If you want to declare your Fortran arrays to start at zero, just
> declare them with a lower bound of zero, like
> 
>    real, dimension(0:n-1) :: a

Can you declare other lower bounds the same way?

[toc] | [prev] | [next] | [standalone]


Page 2 of 3 — ← Prev page 1 [2] 3  Next page →

Back to top | Article view | comp.lang.fortran


csiph-web