6 ms·
I always understood it as some kind of compiler-level macro, where a[b] is expanded into <star>(a + b) and then normal arithmetic rules take over, in which case
by simias 7y ago
I always understood it as some kind of compiler-level macro, where a[b] is expanded into <star>(a + b) and then normal arithmetic rules take over, in which case there's no strangeness as far as I can tell (i.e. it doesn't matter which of a or b is the pointer and which is the integer because C defines both "int + ptr" and "ptr + int" as doing the same thing).
But frankly it's a bad choice if we're talking about C's "esoteric quirks" because both this and Duff's Device are things that you effectively never encounter in the wild (it's the "Buffalo buffalo Buffalo buffalo buffalo buffalo Buffalo buffalo" of the C language, they're interesting to know about but not of much practical use).
There are much better "features" of C to single out, for instance the two million different meanings for the "static" keyword, the fact that arrays declared as function parameters do not behave like arrays but like pointers (hey, you can put "static" in there too now! But it still doesn't make it work like a proper array), the many surprising undefined behaviors regarding integer overflow, aliasing rules etc...