I don't understand this syntax in this old C program, and am not set up to test the code to see what it does. The part I am confused about is the concatenation to the array. I didn't think C could handle auto-typecasting like that, or am I making it too difficult in my head being that its Friday afternoon...
char wrkbuf[1024];
int r;
//Some other code
//Below, Vrec is a 4 byte struct
memcpy( &Vrec, wrkbuf + r, 4 );
Any idea what will happen here? What does wrkbuf become when you concatenate or add an int to it?
wrkbuf + r is the same as &wrkbuf[r]
Essentially wrkbuf when used as in the expression wrkbuf + 4 "decays" into a pointer to the first element. You then add r to it, which advances the pointer by r elements. i.e. there's no concatenation going on here, it's doing pointer arithmetic.
The memcpy( &Vrec, wrkbuf + r, 4 ); copies 4 bytes from the wrkbuf array , starting at the rth element into the memory space of Vrec
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With