[ale] This is legal C:

Bjorn Dittmer-Roche bjorn at sccs.swarthmore.edu
Thu Feb 12 12:29:53 EST 2004


On Thu, 12 Feb 2004, Byron A Jeff wrote:

> On Thu, Feb 12, 2004 at 10:40:09AM -0500, Bjorn Dittmer-Roche wrote:
> > Someone sent me this. It's an interesting oddity. Try it on your
> > favorite C compiler!
>
> What's strange about it. [ is a commutative operator, so a[i] and i[a]
> represent the same thing i.e. *(a+i). The reason the compiler doesn't complain
> is that printf takes a void pointer in that spot, so since the result is a
> char *, no worries.

Well, y'all are too smart I guess -- I always figured the compiler
expected a pointer as a and an int as i in a[i], although I knew how
*(a+i) worked. Perhaps this is more of a novelty with java
programmers.....

	bjorn



More information about the Ale mailing list