structure assignment vs memcpy

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • subramanian100in@yahoo.com, India

    #1

    structure assignment vs memcpy

    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 ?

  • santosh

    #2
    Re: structure assignment vs memcpy

    subramanian100i n@yahoo.com, 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.

    Comment

    • Richard Tobin

      #3
      Re: structure assignment vs memcpy

      In article <1173532974.877 416.135290@8g20 00cwh.googlegro ups.com>,
      subramanian100i n@yahoo.com, India <subramanian100 in@yahoo.comwro te:
      >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
      --
      "Considerat ion shall be given to the need for as many as 32 characters
      in some alphabets" - X3.4, 1963.

      Comment

      Working...