I am trying to understand the following code
uchar abyHeader[100];
i32 = psSHP->nFileSize / 2;
ByteCopy(&i32, abyHeader + 24, 4);
where
#define ByteCopy( a, b, c ) memcpy( b, a, c )
I understand how memcpy works. However, I am not sure what abyHeader + 24 does to abyHeader. I know that if we have a uchar*, this would skip 24 elements and point to the next element. Does the array work the same?
#define. That definition you have there isn't sufficiently robust as the values could be non-trivial. Instead use a function wrapper, even aninlineone. If this is code you've been given it's really sloppy and pretty much pointless since it just shuffles the arguments and obscures what's actually happening, impairing understanding.*(x + n)andx[n]produce the same result, sox + 24is akin to&x[24]or in other words, adding24 * sizeof(uchar)to the pointer.abyHeader) decay to pointers in many situations.abyHeader + 24is the same as&abyHeader[24], so yes, it works the same as with auchar*.memcpydoes. There is no need for a#definemacro there. It's equivalent to replacing a steering wheel for a car with a joystick.