httpd-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Charlie Gordon" <gm...@chqrlie.org>
Subject Re: bug in header files
Date Mon, 28 Jun 2004 18:12:49 GMT
On Monday, Patrick W. thus responded:

Indeed.. Where does that construct come from?

> printf("'N' = %d <-> FALSE[\"NY\"] = %d\n", 'N', FALSE["NY"]);

I have never seend TRUE["NY"], and would have guessed cpp would change
it to 1["NY"] which doesn't mean anything to me. It appears to want to
be "NY"[1] ?! How come it works?

---------

I guess the example code requires some explaining:

In the first case,  TRUE["NY"]  expands to 1["NY"]  which is semantically
interpreted as *(1 + "NY") and therefore computes to 'Y'.
Whereas in the second case, TRUE["NY"] expands to  !FALSE["NY"]  which in
turn expands to  !0["NY"] .
That computes to !*(0 + "NY")  simplified into !*"NY"   or  !'N'   finally
resulting in  the integer value 0.

Unbeknownst to the vast majority of C programmers, subscripting in C is
indeed commutative:

p[i]  is the same as *(p + i)  same as *(i + p)  or i[p].

I've seen it used in obfuscated C code contest submissions, in C puzzles,
and similar teasing tests.

Enjoy,

Charlie Gordon,
The C teaser




Mime
View raw message