Re: [PATCH v2] add, rm, mv: fix bug that prevents the update of non-sparse dirs
- From
Chris Torek <chris.torek@gmail.com>
- Date
- Oct 27, 2021, 22:13 UTC
- Message-ID
- <CAPx1GvcBXi127ujDBNgdpbvc_yB=BpvgSBNN62KYZb=8b52k_A@mail.gmail.com>
- In-Reply-To
- <00a67af9-da41-6df4-afc0-5ae7c7714bfd@gmail.com>
On Tue, Oct 26, 2021 at 11:17 PM Derrick Stolee <stolee@gmail.com> wrote: (regarding a pointer that "backs up one before the beginning of the array" as it were)
> I also see the specification saying this is undefined, but I do not > understand how any reasonable compiler/runtime could do anything > other than store "path - 1" as if it was an unsigned integer. ...
This Standard C rule dates back to old segmented systems. If you put some array A into its own segment, and use only the offset as the "pointer", and the segment offset starts at zero, then A[0] is at "address zero". So the imaginary element at A[-1] is at "address max", and a loop like:
for (p = &A[N]; p >= &A[0]; p--)
is an infinite loop.
In practice nobody is using these architectures today, but the restriction still exists.
Chris