Re: Copying a struct to a larger struct?



"hermes_917@xxxxxxxxx" wrote:
>
> I want to use memcpy to copy the contents of one struct to another
> which is a superset of the original struct (the second struct has
> extra members at the end). I wrote a small program to test this,
> and it seems to work fine, but are there any cases where doing
> something like this could cause any problems?

Why do snaky things in the first place? Just write down what you
want:

struct smaller {
....
} smallguy;

struct bigger {
struct smaller small;
....
} bigguy;

....

bigguy.small = smallguy;

and I find it hard to imagine what could go wrong.

--
"If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers." - Keith Thompson

.



Relevant Pages

  • Re: Structure in CSharp
    ... One is that your _myUnion struct doesn't look to me to be the same as the original struct you've specified. ... You've got as its first field a single byte "_messageType", but the original struct has a 255-byte array named "Data". ... Another thing is that the _olmSYSTEM_INFORMATION struct doesn't look like anything in your original struct definition. ... This may or may not be a problem, but I am left wondering how you got from the original struct definition you posted to the C# declaration you've also posted. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Class vs. Struct - Newbie question & app.
    ... it wont affect the original struct. ... Unless, of course, a member of the struct is a mutable reference ... reference" so to speak, and therefore that method could modify it. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: [PATCH] vlan & net drivers: avoid a 4-order allocation
    ... This patch splits the vlan_group struct into a multi-allocated struct. ... x86_64, the size of the original struct is a little more than 32KB, causing ...
    (Linux-Kernel)
  • Re: Members in a struct
    ... Will it be messy in fetching the values of pointers in a struct ... If you replace the original struct, all your code must be changed to ... Each of the original 19 members is ...
    (comp.lang.c)
  • Re: (: Pointer to struct withing pointer to struct :)
    ... >> is there also memory requested for the second struct inside Person? ... char Nachname; ... struct * Infos MyInfos; ...
    (comp.lang.c)