• =?UTF-8?Q?=e2=80=9cWhy_do_arrays_start_at_0=3f=22?=

    From Lynn McGuire@21:1/5 to All on Fri Aug 26 15:49:51 2022
    XPost: comp.lang.c++

    “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.

    Lynn

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Mr Flibble@21:1/5 to Lynn McGuire on Sat Aug 27 00:44:45 2022
    XPost: comp.lang.c++

    On Fri, 26 Aug 2022 15:49:51 -0500
    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.

    Fortran is retarded.

    /Flibble

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Thomas Koenig@21:1/5 to Lynn McGuire on Sat Aug 27 05:47:44 2022
    XPost: comp.lang.c++

    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

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Thomas Koenig@21:1/5 to gah4@u.washington.edu on Sat Aug 27 09:30:11 2022
    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.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Thomas Koenig@21:1/5 to gah4@u.washington.edu on Sat Aug 27 22:13:05 2022
    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?

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Thomas Koenig@21:1/5 to gah4@u.washington.edu on Sun Aug 28 06:59:19 2022
    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.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Thomas Koenig@21:1/5 to Lynn McGuire on Sun Aug 28 20:17:19 2022
    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).

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Thomas Koenig@21:1/5 to Ron Shepard on Tue Aug 30 17:18:04 2022
    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.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)