memcpy() Behaviour

myhotline_at_gmail.com
Date: 12/30/04


Date: 30 Dec 2004 13:57:56 -0800

hi all

im very confused about using memcpy and i have three
questions....memcpy takes a pointer to src and a pointer to dest and
copies src to destination...but im very confuzed about when to use '&'
operator while using memcpy....i have code that use '&' and the code
that call memcpy without '&'
like is the following same
Quest1

---
struct str{
int name;
}
struct stru{
int aname;
}
str *s;
s->name = 10;
stru *s1;
s1->aname = 100;
//now what about following two lines
memcpy(s->name,s1->aname,sizeof(int));
memcpy(&(s->name),&(s1->aname),sizeof(int));
if above two memcpy are same why? if not, why???
Quest2
-------
one more thing how can i use macros in memcpy
like if i have
#define TRUE 1
then how can i copy TRUE into s1->name.
Quest3
---------
Moreover , if i copy two INTS as in
int a;
int b;
memcpy(a,b,sizeof(int));
memcpy(&a,&b,sizeof(int));
Though i have not tested above but as far as i remember both of the
above memcpy lines will compile and work..aint it koz of the reason
that memcpy upon receving arguments cast them......???(well i have no
idea :( )...
..Thanks a lot for your time ..please revert as soon as possible
Greetings and Happy New Year..
Waqas
-------------------------------------
"You laugh at me because i am different, i laugh at you because you are
all the same." - Kurt Cobaine


Relevant Pages

  • Re: memcpy() Behaviour
    ... > questions....memcpy takes a pointer to src and a pointer to dest and ... > int aname; ... Your compiler should complain about that. ... of two `int's and told memcpy() to copy a `int' worth of bytes. ...
    (comp.lang.c)
  • Re: Implementing my own memcpy
    ... > src, int bytes) { ... > Now if I want to copy the bytes from src to dest, ... Are you trying to achieve the exact same behaviour as memcpy? ...
    (comp.lang.c)
  • Re: memcpy() Behaviour
    ... >im very confused about using memcpy and i have three ... >questions....memcpy takes a pointer to src and a pointer to dest and ... >int aname; ... compiler will not see the TRUE, ...
    (comp.lang.c)
  • Re: re-assignment of a struct
    ... Forgot to add that it works with memcpy(). ... If you are willing to change p1 from an array of struct to a pointer ...
    (comp.lang.c)
  • Re: long type in solaris
    ... I need to copy a long type value into a char string using a memcpy ... If 'value' is a long int variable then this looks rather strange. ... what ends up in string isn't going to be a textual representation ...
    (comp.lang.c)