Path: utzoo!utgpu!attcan!uunet!mcvax!cernvax!hjm From: hjm@cernvax.UUCP (Hubert Matthews) Newsgroups: comp.lang.c Subject: Re: "for" loops in C ... Message-ID: <867@cernvax.UUCP> Date: 3 Nov 88 17:20:47 GMT Reply-To: hjm@cernvax.UUCP (Hubert Matthews) Organization: CERN European Laboratory for Particle Physics, CH-1211 Geneva, Switzerland Lines: 25 In article <10742@cup.portal.com> ts@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