On Jun 18, 2007, at 4:48 PM, Andy Lester wrote:
Is there a reason we use
memcpy( dest, src, sizeof(FOO) );
instead of
*dest = *src;
The latter should be the exact same code, but be much less likely to
be screwed up.
No, they're extremely different. In the first, the data of FOO is
copied to dest, so dest can be modified without changing src. In the
second, src and dest point to the same data. If you modify one, all
are modified. If you want to clone something, or just move it to a new
location, you can't just set the pointer. If I'm missing something,
well maybe someone who knows more can provide more advice.
At the very least we should be using:
memcpy( dest, src, sizeof(*dest) );
Of course, I'm only talking about when we're passing around structs.
Clearly this won't work everywhere.
--
Andy Lester => [EMAIL PROTECTED] => www.petdance.com => AIM:petdance