"for" loops in C ...
Hubert Matthews
hjm at cernvax.UUCP
Fri Nov 4 03:20:47 AEST 1988
In article <10742 at cup.portal.com> ts at cup.portal.com (Tim W Smith) writes:
>I don't know about i[ptr] being less readable than ptr[i]. Most people I
>have heard would say when describing an algorithm in English, "Then you take
>the ith element of the array and multiply by foo". i[array]*foo has the
>words in C in the same order they would be spoken.
>
> Tim Smith
Take a look at Knuth. He uses a notation like next(a) to represent the
C statement a.next. His argument goes something like this. The
function next() is applied to a variable argument - next(a) or next(b)
- just like good ol' array indexing in FORTRAN - array(i). Well, why
not? BCPL made it very obvious that a[i] and i[a] are the same; it
used (uses?) a!i to mean *(a+i). This works fine even for structure
access, until you have strong typing. Guess what BCPL didn't have? I,
personally, IMHO, would be happy with a[next] for structure access or
a.i for array access. Isn't it all really the same and just a matter
of conditioning? As I said, it's not obvious how strong typing would
work in such a language, but it would eliminate one more thing for the
compiler writers to have to do *and get right*. :-)
--
Hubert Matthews
More information about the Comp.lang.c
mailing list