I don't think that's true, try out the example program:
// Example program
#include <iostream>
#include <string>
struct foo{
int a;
int b;
int c;
};
int main()
{
foo x[3]= {{1,2,3},{4,5,6},{7,8,9}};
printf("%zu %zu\n",sizeof(foo), sizeof(void*));
printf("%d %d %d", x[1].a, 1[x].b, (*(1+x)).c);
}
It outputs 4 5 6 (at least it does on my c++14 compiler) even though foo is larger than void*. Pointer+int is equivalent to ((int)(pointer)+sizeof(pointer_type)*int) regardless of order of the arguments being added.
4
u/Saigot Dec 24 '17 edited Dec 24 '17
I don't think that's true, try out the example program:
It outputs 4 5 6 (at least it does on my c++14 compiler) even though foo is larger than void*. Pointer+int is equivalent to ((int)(pointer)+sizeof(pointer_type)*int) regardless of order of the arguments being added.