A patch was posted to gcc that provides something called vector subscripting to g++ (gcc already had it).
If a is an array and i is an int then i[a] is legal and equal to a[i].
double a[]{0.0, 1.0, 2.0, 3.0}; // C++11 style but would work in C++98 style too.
assert(a[2] == 2.0);
assert(2[a] == 2.0);
So, is this legal and standard C/C++ or is it a gcc extension?
Actually, Google shows MS Developer Studio has this too. I looked in the C++ standard and didn’t see it though.
The patch has nothing to do with
i[a]being equivalent toa[i]; that has always been the case, in both languages. Unless user-defined types are involved,a[i]is defined as being equivalent to*(a+i), and addition is commutative.The patch concerns vector datatypes (not to be confused with the C++
std::vectorclass template), a GCC language extension to support vector processing instructions. According to the patch notes, they were subscriptable like arrays in C but not C++, and this patch adds that feature to C++.