Acording to the Post: With arrays, why is it the case that a[5] == 5[a]?
Where is claimed, that a[5]
is equal to 5[a]
.
I'm asking my self, is this true?
While I aggree that E1[E2] is identical to (*((E1)+(E2)))
But I would claim: Given a declaration of
int a[sizeI];
where if (sizeI > 5)
has to be true
I would aggree that a[5]
is ok.
But related to the cite from ISO/IEC:9899
Apendix J.2 Undefined behavior:
— An array subscript is out of range, even if an object is apparently accessible with the given subscript (as in the lvalue expression
a[1][7]
given the declaration inta[4][5]
) (6.5.6).
Is (if I get it correct from the document) 5[a]
"apparently accessible" but the "array subscript is out of range"
So I would overall disaggree to the OP I linked,
as that a[5]
is in the given case well defined and 5[a]
is undefined behaviour.
So, am I right? Or have I forgotten to consider something important?
EDIT:
my claim doesn't imply that
E1[E2] is identical to (*((E1)+(E2)))
would be incorrect.
and also 6.5.2.1 Array subscripting point 2
just says that they are arithmeticaly identical.
But nothing is said like: (*((E1)+(E2)))
can't achive UB.
So while I know this section, I can't find there anything thatdestroys my claim
Also Note:
As you allready should see in my first sentence, I'm asking a different question to the related to the "problem" stated by
With arrays, why is it the case that a[5] == 5[a]?
So please stop marking it as duplicate of that one.