I know this has been hashed over a number of time, but I have come across a case today that shook my understanding of the pointer math/ array index.
As I have allways understood it, &mybuff[10] and (&mybuff+10) are equivilent ways of referancing the same memory.
However I spent the morning fighting a case where:
memcpy(&mybuff+10,&in,8);
overflowed the buffer, when compiled with optimization on and worked just fine when compiled for debugging.
While athe same time,
memcpy(&mybuff[10],&in,8);
worked just fine in both cases.
Many thanks for any ideas or pointers.
&mybuff[10]evaluates to&(*(mybuff+10)), which is different from&mybuff + 10. Remember that postfix operators like[]have higher precedence than unary operators like&.