Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

C: Assigning structures

Name: Anonymous 2010-07-24 2:09

suppose we have the following type:

typedef struct {
    int bar;
    int baz;
    int foo;
} Something;


In order to do a copy, I usually do something like:

Something a, b;
...
memcpy ((void *) &a, (const void *) &b, sizeof(Something));

But also the following is legal (and far more quick to write).

Something a, b;
...
a = b;

Is there any disadvantage in doing the second one?

Name: Anonymous 2010-07-28 15:00

>>35
void (*mymemcpy)(void *, const void *, size_t) = &memcpy; and then use mymemcpy instead of memcpy.

Name: Anonymous 2010-07-28 15:07

>>35
Oh yeah, and don't forget -fno-strict-aliasing. Fucking gcc developers.

Name: Anonymous 2010-07-28 15:18

/* A subroutine of gimplify_modify_expr.  Replace a MODIFY_EXPR with
   a call to __builtin_memcpy.  */


I think that's it.

Name: Anonymous 2010-07-28 17:46

memecpy

Name: Anonymous 2010-07-28 18:09

>>44
I lol'd.  Well, I couldn't help it.

Name: Anonymous 2010-07-28 18:36

>>35,40
I can't come up with some scheme to make GCC handle memcpy and = differently
I want it to use the builtin memcpy, otherwise it's pointless.
Are you listening to yourself? Have you not read a single thing anyone else is saying? They're the same goddamn thing. The built-in memcpy() is not even a real function call. They can't behave differently because by definition they do the same thing.

You're not making any sense.

Name: Anonymous 2010-07-28 18:42

>>46
Feel free to discuss how fnop and nop differ also.

Name: Anonymous 2010-07-28 19:16

>>46
They can't behave differently because by definition they do the same thing.
Correct, I looked that up in the source code for GCC (>>43).  I had expected memcpy to be transformed into an assignment, but it was the other way around.

Name: Anonymous 2010-07-28 20:02

>>48
Well duh it's the other way around. All assignments can be transformed into memcpy, but not all memcpy can be transformed into assignments.

Name: Anonymous 2010-07-28 20:04

>>49
Erm, well excuse me.  Meant to say "struct assignments".  Obviously FP->integer assignments and such can't be turned into memcpy.

Name: Anonymous 2010-07-28 20:04

>>49
Actually, just imagine a memcpy of arbitrary size transforming into a struct assignment of the same size.

Name: Anonymous 2011-02-03 3:53


Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List