[ale] This is legal C:

Byron A Jeff byron at cc.gatech.edu
Thu Feb 12 11:53:09 EST 2004


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.

BAJ
> 
> 	bjorn
> 
> --------------------------------------------------
> 
> /* Find the strangeness! Spotted on kuro5hin... */
> #include <stdio.h>
> 
> char *foo[] = {"what", "the", "heck", "is", "this"};
> 
> int main(int argc, char **argv)
> {
>   int j=2;
>   printf("Test: %s\n", j[foo]);
>   return 0;
> }
> _______________________________________________
> Ale mailing list
> Ale at ale.org
> http://www.ale.org/mailman/listinfo/ale



More information about the Ale mailing list