By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,159 Members | 956 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,159 IT Pros & Developers. It's quick & easy.

structure assignment vs memcpy

P: n/a
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 ?

Mar 10 '07 #1
Share this Question
Share on Google+
2 Replies


P: n/a
su**************@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.

Mar 10 '07 #2

P: n/a
In article <11**********************@8g2000cwh.googlegroups.c om>,
su**************@yahoo.com, India <su**************@yahoo.comwrote:
>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.
Mar 10 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.