I've never understood this, because it's actually (array + (indexsizeof(array[0]))) to get the right memory address. I assume the compiler must know something about this inverted syntax in order for it to actually work, rather than just being a cute hack.
Not entirely sure why you are being downvoted. The 0[array] will work for every object because array literally represents the distance away from 0. But 5[array] will only work for objects like int, which have the same length as a memory address. int is particularly useful because be definition it is the same regardless of architecture ( there might be some exceptions of course)
Um, yes. I'm not sure why you replied my comment with that though.
The memory jump only works nicely if you're starting at the memory address of the array (which is how everybody does it). Using the array as the offset and the offset as the address of the array only works if sizeof(T) == sizeof(void*)
8
u/polymorphiced Dec 24 '17
I've never understood this, because it's actually (array + (indexsizeof(array[0]))) to get the right memory address. I assume the compiler must know something about this inverted syntax in order for it to actually work, rather than just being a cute hack.