3 ms·
No; a[5] evaluates to (a + 5), and 5[a] as (5 + a). Separately: e + p where e : integer-type and p : pointer-type p + e where e : integer-type and p :
by barrkel 15y ago
No; a[5] evaluates to (a + 5), and 5[a] as (5 + a).
Separately:
e + p where e : integer-type and p : pointer-type
p + e where e : integer-type and p : pointer-type
are evaluated roughly as:
(pointer-type)(e*sizeof(*p) + (size_t)p)
(pointer-type)((size_t)p + e*sizeof(*p))
but these are very rough translations, because we're wandering into implementation-defined territory (substitute uintptr_t for size_t as desired etc).
The type analysis on the addition is reminiscent of e.g. promoting integers to floats:
i + f where i : integer-type and f : float-type
f + i where i : integer-type and f : float-type
correspondingly:
(float-type)i float-type::+ f
f float-type::+ (float-type)i
The '+' built-in is overloaded in C.