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-27 11:25

>>19

#include <stdio.h>

void * memcpy(void * destination, const void * source, size_t num)
{
    return "CPY MY MEM";
}

int main()
{
    printf("%s\n", (char*)memcpy("HAXUS", "THE REIMPLEMENTOR", 0));
    printf("%s\n", (char*)memcpy("HAXUS", "THE REIMPLEMENTOR", 1));
    return 0;
}

Can you guess the results?

$ gcc -dumpversion
3.4.6
$ gcc test.c -Wall -pedantic -ansi
$ ./a.out
HAXUS
CPY MY MEM

Funny, ain't she?

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