G
glen herrmannsfeldt
Malcolm McLean said:On 05/20/2013 04:36 AM, Malcolm McLean wrote:
I don't see the connection between your example of counting out
42 beans, and array[42].
Someone might be able to count beans, but not able to add.
You couldn't ask for 42+5 beans, but could ask for 42 beans,
then for five more, which they would count.
If you go to the bank to cash a check for $100, and ask for it
in $5 bills, they will count it out by fives. (5, 10, 15, 20 ...).
They could just count the 20 bills and multiply by five, but it
is tradition.
The defined behavior of array[42] does
not involve successively stepping through the first 42 positions
in the array; it's defined in terms of pointer addition, which in
turn is defined in terms of integer addition as applied to
positions within an array, something I'd consider to
unambiguously be "arithmetic".
Internally, yes, the processor will calculate 0x1234 + 42 to
give an address. But the programmer doesn't see that.
On many processors, the program has to compute the address
of array element 42, possibly as 0x1234+4*42. Note, though,
that VAX has an indexed addressing mode that includes the size
of the element being addressed. You can put 0x1234 in one
register, 42 in another, and get the appropriate array element.
He just sees "take array and go 42 positions to the right". Like
going to a street called array avenue and finding house 42.
That's counting on.
(Then normally you step through an array, you seldom see
array[42] = x in real code, it's almost always
for(i=0;i<42;i++)
array = x.
Very clearly this is counting on.)
Or maybe:
for(i=0;i<42;i++) *array++ = x;
(If array was a pointer variable, and its value wasn't needed again.)
-- glen