On Fri, 20 Sep 2024, Paul Winalski wrote:
On Thu, Sep 19, 2024 at 7:52 PM Rich Salz
<rich.salz(a)gmail.com> wrote:
In my first C programming job I saw the source to V7 grep which
had a "foo[-2]" construct.
That sort of thing is very dangerous with modern compilers. Does K&R C
require that variables be allocated in the order that they are declared? If
not, you're playing with fire. To get decent performance out of modern
processors, the compiler must perform data placement to maximize cache
efficiency, and that practically guarantees that you can't rely on
out-of-bounds array references.
[...]
Unless I'm mistaken (quite possible at my age), the OP was referring to
that in C, pointers and arrays are pretty much the same thing i.e.
"foo[-2]" means "take the pointer 'foo' and go back two
things" (whatever
a "thing" is).
C is just a high level assembly language; there is no such object as a
"string" for example: it's just an "array of char" with the last
element
being "\0" (viz: "strlen" vs. "sizeof".
What's the length of "abc" vs. how many bytes are needed to store it?
Things were much simpler when V7 was written.
Giggle... In a device driver I wrote for V6, I used the expression
"0123"[n]
and the two programmers whom I thought were better than me had to ask me
what it did...
-- Dave, brought up on PDP-11 Unix[*]
[*]
I still remember the days of BOS/PICK/etc, and I staked my career on Unix.