473,320 Members | 2,112 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

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 ?

Mar 10 '07 #1
2 12962
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Brian K. Michalk | last post by:
I know I can assign default values to a structure during initialization, but I have a routine that accumulates a lot of floats into an array, and then I would like to assign them to a (reference to...
15
by: Sourcerer | last post by:
Hi all. Can I do this to duplicate the contents of struct a in struct b struct myStruct a, b, *aptr, *bptr; aptr = a; bptr = b; Do something to initialize contents of structure a...
12
by: anonymous | last post by:
Hi folks, I am in a fix trying to copy data to an array which is member of a structure. What I am doing right now is: char array = {0,1,2,3,4,5,6,7}; memcpy(structure.array, array, 8); Is...
4
by: gladhuman | last post by:
Hi, Let's assume that I have the following structure and the following array: struc My_struct { char var_one; char var_two; char var_three;
2
by: Rick Anderson | last post by:
I want to store a "va_list" in a structure (which gets passed around from function to function). I cannot use the va_copy() routine to create a copy of the varargs (it looks like it uses stack...
38
by: sam_cit | last post by:
Hi, I have the following Struct, Struct Sample { int i; char *p; };
7
by: Pep | last post by:
I'm getting weird results at the moment so thought I'd rebase my knowledge of c++ storage with your help :) I have a class used as a type in a struct and the struct is handled by a 3rd party...
5
by: sam_cit | last post by:
Hi Everyone, I was just wondering, about the overloaded assignment operator for user defined objects. It is used to make sure that the following works properly, obj1 = obj; so the...
6
by: James H. Newman | last post by:
I have the following: typedef unsigned char T ; T y = { 0x22, 0x33 } ; I now define unsigned short x ;
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.