structure assignment vs memcpy

Discussion in 'C Programming' started by subramanian100in@yahoo.com, India, Mar 10, 2007.

  1. , India

    , India Guest

    Suppose I need to assign one structure to another.
    Should each member of the structure be assigned individually or can
    memcpy be used ?

    Since the compiler can add padding bytes, which approach is always
    safer ?
     
    , India, Mar 10, 2007
    #1
    1. Advertising

  2. , India

    santosh Guest

    , India wrote:
    > Suppose I need to assign one structure to another.
    > Should each member of the structure be assigned individually or can
    > memcpy be used ?
    >
    > Since the compiler can add padding bytes, which approach is always
    > safer ?


    Simply assign one object to another with the assignment operator.
    Structure assignments have been supported since C90.

    Of course if you only want to assign some members of a struct object
    to another, then you'll have to do it manually.

    Using memcpy is not usually necessary, since the language directly
    supports copying structures.
     
    santosh, Mar 10, 2007
    #2
    1. Advertising

  3. In article <>,
    , India <> wrote:

    >Suppose I need to assign one structure to another.
    >Should each member of the structure be assigned individually or can
    >memcpy be used ?


    There seems to be a whole bunch of you doing the same course, asking
    the same questions over and over again. Why don't you get together and
    nominate one of you to do all the homework?

    -- Richard
    --
    "Consideration shall be given to the need for as many as 32 characters
    in some alphabets" - X3.4, 1963.
     
    Richard Tobin, Mar 10, 2007
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Sourcerer

    use memcpy() to copy one structure to another

    Sourcerer, Jun 15, 2004, in forum: C Programming
    Replies:
    15
    Views:
    54,679
    Dan Pop
    Jun 18, 2004
  2. nagy
    Replies:
    36
    Views:
    1,024
    Terry Reedy
    Jul 20, 2006
  3. gsyoon
    Replies:
    4
    Views:
    399
    gsyoon
    Aug 11, 2005
  4. aiooua

    simple assignment of structs vs. memcpy

    aiooua, Mar 10, 2007, in forum: C Programming
    Replies:
    5
    Views:
    479
    aiooua
    Mar 10, 2007
  5. kuyper

    memcpy() where assignment would do?

    kuyper, Aug 23, 2007, in forum: C Programming
    Replies:
    18
    Views:
    558
    kuyper
    Aug 27, 2007
Loading...

Share This Page