You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
"If the * operator, either explicitly or implicitly as a result of subscripting, is applied to this pointer, the result is the pointed-to (n − 1)-dimensional array, which itself is immediately converted into a pointer."
and then in an Example inside that Note, describing int x[3][5];
"In the expression x[i] which is equivalent to *(x+i), x is first converted to a pointer as described; then x+i is converted to the type of x, which involves multiplying i by the length of the object to which the pointer points, namely five integer objects. The results are added and indirection applied to yield an array (of five integers), which in turn is converted to a pointer to the first of the integers."
I see multiple issues:
"which itself is immediately converted into a pointer." is wrong: both explicit * and subscripting yield array lvalues, not pointers.
"x+i is converted to the type of x" makes no sense: the type of x+i is int(*)[5] and it is not converted to anything, definitely not to the type of x, which is int[3][5]
"multiplying i by the length of the object to which the pointer points" makes sense at assembly level, but is not how pointer arithmetic is defined in expr.add/4: x+i yields a pointer to the i'th element of x. In fact, the note just above this one gets it right with "E1[E2] refers to the E2-th member of E1"
"which in turn is converted to a pointer to the first of the integers" is again prematurely decaying an array: x[i] or, equivalently, *(x+i) is an int[5] lvalue, not a pointer.
The text was updated successfully, but these errors were encountered:
A note in [dcl.array]/7 says
"If the * operator, either explicitly or implicitly as a result of subscripting, is applied to this pointer, the result is the pointed-to (n − 1)-dimensional array, which itself is immediately converted into a pointer."
and then in an Example inside that Note, describing
int x[3][5];
"In the expression
x[i]
which is equivalent to*(x+i)
,x
is first converted to a pointer as described; thenx+i
is converted to the type ofx
, which involves multiplyingi
by the length of the object to which the pointer points, namely five integer objects. The results are added and indirection applied to yield an array (of five integers), which in turn is converted to a pointer to the first of the integers."I see multiple issues:
x+i
is converted to the type ofx
" makes no sense: the type ofx+i
isint(*)[5]
and it is not converted to anything, definitely not to the type ofx
, which isint[3][5]
i
by the length of the object to which the pointer points" makes sense at assembly level, but is not how pointer arithmetic is defined in expr.add/4:x+i
yields a pointer to the i'th element of x. In fact, the note just above this one gets it right with "E1[E2] refers to the E2-th member of E1"x[i]
or, equivalently,*(x+i)
is anint[5]
lvalue, not a pointer.The text was updated successfully, but these errors were encountered: