Considering the following snippet, and for both C and C++ languages, is:
int t[2] = { 0, 1 };
*( (int *)( (char *)t + sizeof(int) ) ) = 2;
always equivalent to:
int t[2] = { 0, 1 };
t[1] = 2;
?
It might sound weird but I imagined some reasons why it could be false on some platforms:
charpointer increment could go in a reverse way thanintpointer, unless it is not authorized by the standard (in this case I would like to find where the standards states so)the cast from
int *tochar *could be unsafe because there is not guaranty that their size are the same (and in this case, could it work with an intermediate cast tovoid *?), and because the standard does not guaranty that casting tochar *and then to a pointer to any type is safe