Re: memcpy

2007-06-21 Thread Andy Lester
ce there a bunch of places we're doing memcpy()s with math for multiple structs. I'll work on that today. Getting rid of the math may be the best reason to use a macro yet. Andy -- Andy Lester => [EMAIL PROTECTED] => www.petdance.com => AIM:petdance

Re: memcpy

2007-06-20 Thread Allison Randal
Andy Lester wrote: I guess I don't see the need to document a standard C behavior with a macro. If you had read all the way through the message, you would see that the biggest benefit is the ability to hang debugging hooks off the macro. We have a number of these kinds of debugging hooks t

Re: memcpy

2007-06-20 Thread Andy Lester
On Jun 20, 2007, at 1:05 PM, Mark J. Reed wrote: Incrementing a var is much less likely to have unpredictable effects due to modifying the wrong memory. Sure, x might be a pointer, and things might gang agley there, but pointers getting set to the wrong type of pointee is a pretty common probl

Re: memcpy

2007-06-20 Thread Mark J. Reed
On 6/20/07, Andy Lester <[EMAIL PROTECTED]> wrote: My point is that *d = *s; is no more a weird cryptic construct than n++; or while (*s) *d++ = *s++; for that matter. That's a very good point. As you said in the original message, all you need is *dest = *src; since the c

Re: memcpy

2007-06-20 Thread Mark J. Reed
On 6/20/07, Andy Lester <[EMAIL PROTECTED]> wrote: I guess I don't see the need to document a standard C behavior with a macro. We don't have #define inc(x) (x)++ do we? Incrementing a var is much less likely to have unpredictable effects due to modifying the wrong memory. Sure, x might

Re: memcpy

2007-06-20 Thread Andy Lester
On Jun 20, 2007, at 11:50 AM, Allison Randal wrote: I wasn't entirely happy with either option, so I asked around a bit for other ideas. I like the macro approach below, it gives us both self documentation and better checking for the size of the two structs. I guess I don't see the need

Re: memcpy

2007-06-20 Thread Allison Randal
TED]> To: Allison Randal <[EMAIL PROTECTED]> This can be a bit brittle -- you have to be careful when changing the type of dst else you could end up with over or underflow. memcpy(dst, src, sizeof(FOO)); I do like memcpy because it serves as a red flag that a potentially medium to large si

Re: memcpy

2007-06-19 Thread Leopold Toetsch
Am Montag, 18. Juni 2007 23:48 schrieb Andy Lester: > 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. I'm usin

Re: memcpy

2007-06-19 Thread Andy Armstrong
On 19 Jun 2007, at 08:48, Joshua Isom wrote: 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 extr

Re: memcpy

2007-06-19 Thread Joshua Isom
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 F

memcpy

2007-06-18 Thread Andy Lester
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. At the very least we should be using: memcpy( dest, src, sizeof(*dest) ); Of course, I'm only talking about