Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

I surely do hope that's a syntax error. -- Larry Wall in <199710011752.KAA21624@wall.org>


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

SubjectAuthor
o “Why do arrays start at 0?"Paavo Helde

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

<teg5v0$lrls$1@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.fortran comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: eesn...@osa.pri.ee (Paavo Helde)
Newsgroups: comp.lang.fortran,comp.lang.c++
Subject: Re: “Why do arrays start at 0?"
Date: Sun, 28 Aug 2022 19:43:11 +0300
Organization: A noiseless patient Spider
Lines: 58
Message-ID: <teg5v0$lrls$1@dont-email.me>
References: <tebblf$2gpm$1@dont-email.me> <tedr4l$1cc0$1@gioia.aioe.org>
<tedt6n$757$1@gioia.aioe.org> <tee5i3$cqm$4@newsreader4.netcologne.de>
<teeo2r$8tl$1@gioia.aioe.org>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Sun, 28 Aug 2022 16:43:12 -0000 (UTC)
Injection-Info: reader01.eternal-september.org; posting-host="ee71f962ccaee161d1e5540bb6555083";
logging-data="716476"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+/tp/Vzrvl4dxN5H2Q31bohgXWWz7c8v0="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.13.0
Cancel-Lock: sha1:lYWozi6kAvlOBHVwJZOy9wgSJQg=
In-Reply-To: <teeo2r$8tl$1@gioia.aioe.org>
Content-Language: en-US
 by: Paavo Helde - Sun, 28 Aug 2022 16:43 UTC

28.08.2022 06:40 Lynn McGuire kirjutas:
> On 8/27/2022 5:24 PM, Thomas Koenig wrote:
>> Lynn McGuire <lynnmcguire5@gmail.com> schrieb:
>>> On 8/27/2022 2:26 PM, Fred. Zwarts wrote:
>>>> Op 26.aug..2022 om 22:49 schreef Lynn McGuire:
>>>>> “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
>>>>>
>>>>
>>>> I assumed that it was done because in C x[i] is equivalent to *(x+i).
>>>
>>> Yup.  So Fortran x(i) is equivalent to *(x+i-1).
>>
>> To be more precise, x(i) is equivalent to *(x+i-lbound(x,1))
>>
>>> Or, the x is
>>> subtracted from first: x--; *(x+i);.
>>
>> That's an f2c idiom, which is not valid C, AFAIK, because
>> the pointer would point before the actual array.
>
> While the second pointer is a bad pointer, it is not a illegal pointer.

The C++ standard (n4861) calls this "an invalid pointer value".

For pointers which continue to point to freed objects, it says "A
pointer value becomes invalid when the storage it denotes reaches the
end of its storage duration".

About invalid pointers it says:
"Indirection through an invalid pointer value and passing an invalid
pointer value to a deallocation function have undefined behavior. Any
other use of an invalid pointer value has implementation-defined behavior."

There is also a footnote:
"Some implementations might define that copying an invalid pointer value
causes a system-generated runtime fault."

So, while technically one might get away with the "x--" trick most of
the time with the linear memory addressing used by mainstream
implementations nowadays, still various diagnostic tools would mark
these as invalid pointers, causing an avalanche of errors whenever you
want to solve your actual memory access problems.

I guess it might also subvert automatic garbage collection which is
sometimes used with C++. There is a special case of "safely-derived"
pointer values which I suspect is made exactly for making GC possible,
and changing the pointer value to x-1 would apparently ruin this.

And with segmented memory, like with 16-bit x86, it might cause all kind
of surprises.

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor