Re: Copying a struct to a larger struct?



On 27 Jul 2005 12:32:08 -0700, "hermes_917@xxxxxxxxx"
<kgarrison@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?

There is no guarantee that the padding in the common part of the two
structs is the same. It is also possible for the shorter struct to
have padding at the end but in the longer struct there could be an
actual member at the same offset.


<<Remove the del for email>>
.



Relevant Pages

  • Re: padding?
    ... Padding may change randomly or never at all, and you can blot over it ... struct s { ... type to access the "hidden" members. ... There is one case where unnamed bit-fields are ...
    (comp.lang.c)
  • Re: tokens concat
    ... I think that if the struct contains only members of type int, ... Do you mean that excluding padding; in this case st should place all ... Yes, if all members were of type int, there would be no padding ... tricks to ensure that the code will compile only when this test is ...
    (comp.lang.c)
  • Re: Structure size directives
    ... When you target a specific architecture, the alignment requirements are know apriori, so system developers do make use of explicit alignment and knows what they are doing. ... struct foo obj; ... offset of 4 bytes, and with the #pragma pack, it would be allocated at ... There are really two different cases here, you talk about the usage of "pack" to minimize padding in a struct, while I talk about the "pack " usage, which specify alignmentof struct members. ...
    (comp.lang.c)
  • Re: tokens concat
    ... I think that if the struct contains only members of type int, ... Do you mean that excluding padding; in this case st should place all ... Yes, if all members were of type int, there would be no padding ... Since a compiler may add padding after the last element of a ...
    (comp.lang.c)
  • Re: How come C allow structure members to be addressed like an array ?
    ... but I'm open to correction!) ... i.e. whether there are any padding bytes in the struct that would ... And it seems on anything but a DS9K it is save to assume that no padding ... bytes are between the members, but it is very well possible ...
    (comp.lang.c)