Frank Schönmann: Kleines C-Rätsel

Beitrag lesen

hi!

Im Prinzip kann man sagen, Summanden sind vertauschbar, und der
Compiler sucht sich dan schon raus, welchen der Werte er als Basis
nimmt und welchen er mit dem sizeof des basistyps multiplizieren
muss.

Jepp. In einer C-FAQ hab ich dazu noch folgendes gefunden:

=== cut ===
6.11  I came across some "joke" code containing the "expression"
      5["abcdef"] . How can this be legal C?

A: Yes, Virginia, array subscripting is commutative in C. This
curious fact follows from the pointer definition of array
subscripting, namely that a[e] is identical to *((a)+(e)), for *any*
two expressions a and e, as long as one of them is a pointer
expression and one is integral. This unsuspected commutativity is
often mentioned in C texts as if it were something to be proud of,
but it finds no useful application outside of the Obfuscated C
Contest (see question 20.36).

References: Rationale Sec. 3.3.2.1; H&S Sec. 5.4.1 p. 124, Sec. 7.4.1
pp. 186-7.
=== cut ===

Quelle: http://www.faqs.org/faqs/C-faq/faq/.

bye, Frank!