Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c++ > #86125
| From | Thomas Koenig <tkoenig@netcologne.de> |
|---|---|
| Newsgroups | comp.lang.fortran, comp.lang.c++ |
| Subject | Re: “Why do arrays start at 0?" |
| Date | 2022-08-27 22:22 +0000 |
| Organization | news.netcologne.de |
| Message-ID | <tee5f1$cqm$3@newsreader4.netcologne.de> (permalink) |
| References | <tebblf$2gpm$1@dont-email.me> <tecb60$5sh$1@newsreader4.netcologne.de> <tedqnk$1414$1@gioia.aioe.org> |
Cross-posted to 2 groups.
d thiebaud <thiebauddick2@aol.com> schrieb:
> 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?
Yes.
You can, since 1991, when Fortran 90 was released, do
real, dimension(from:to) :: a
where from and to are arbitrary integer expressions. (If to <
from, then you get a zero-sized array, which is perfectly valid
and which just happens to have size zero and no element).
(In Fortran, you cannot declare variables in the middle of
code. If you want to do that, Fortran 2008 introduced the
BLOCK construct for declaring variables, much like
C's or C++'s { and }, so you can do
read (*,*) from, to
block
real, dimension(from:to) :: a
! Use a here
end block
Back to comp.lang.c++ | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
“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?" 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: 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?" Louis Krupp <lkrupp@invalid.pssw.com.invalid> - 2022-08-26 16:08 -0600
Re: “Why do arrays start at 0?" Gawr Gura <gawrgura@mail.hololive.com> - 2022-08-26 15:18 -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?" 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?" 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?" 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?" 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?" Juha Nieminen <nospam@thanks.invalid> - 2022-08-29 11:15 +0000
csiph-web