J
James Kuyper
On 05/23/2013 06:00 PM, Malcolm McLean wrote:
....
No - we do it for two reasons that have nothing to do with that. First
of all, all of the memory hardware I'm familiar with provides built-in
instructions that do the equivalent of performing addition, NOT counting
on. Those instructions are the ones that all C implementations I'm
familiar with use to implement subscripting. I don't know of any memory
hardware that fails to provide such instructions, nor of any C compiler
that fails to use them for that purpose. Of course, there's lots of
hardware that I'm not familiar with, and lots of C implementations, too,
so I can't be sure there aren't obscure systems that work that way.
However, your words imply that implementation of array subscripts as
"counting on" is not merely an obscure alternative to more mainstream
approaches; it's not even merely the mainstream approach; you imply that
it's universal, and I'm quite sure that's not the case.
The second reason, which is actually the consequence of the first
reason, is that the C standard defines array subscripting in terms of
conversion of the array lvalue into a pointer the start of the array,
and it defines pointer subscripting in terms of addition.
In what sense is that "real"? Can you cite any examples of any
implementation of C where array[n] is implemented in a way that makes it
an O(n) process? I'd like to make sure that I don't use that implementation.
....
Array notation you can understand purely in terms of op zero. You
don't need to abstract it to addition. We tend to do this because
we're so familiar with addition.
No - we do it for two reasons that have nothing to do with that. First
of all, all of the memory hardware I'm familiar with provides built-in
instructions that do the equivalent of performing addition, NOT counting
on. Those instructions are the ones that all C implementations I'm
familiar with use to implement subscripting. I don't know of any memory
hardware that fails to provide such instructions, nor of any C compiler
that fails to use them for that purpose. Of course, there's lots of
hardware that I'm not familiar with, and lots of C implementations, too,
so I can't be sure there aren't obscure systems that work that way.
However, your words imply that implementation of array subscripts as
"counting on" is not merely an obscure alternative to more mainstream
approaches; it's not even merely the mainstream approach; you imply that
it's universal, and I'm quite sure that's not the case.
The second reason, which is actually the consequence of the first
reason, is that the C standard defines array subscripting in terms of
conversion of the array lvalue into a pointer the start of the array,
and it defines pointer subscripting in terms of addition.
... But really array[42] isn't
"take array, add 42, find the value and dereference it", it's
"take array and count on 42 places".
In what sense is that "real"? Can you cite any examples of any
implementation of C where array[n] is implemented in a way that makes it
an O(n) process? I'd like to make sure that I don't use that implementation.