[Ilugc] Structure copy behaviour

  • From: skarra@xxxxxxxxx (Sriram Karra)
  • Date: Mon May 28 13:34:05 2007

On 5/24/07, Vaidhy <vaidhy@xxxxxxxxxx> wrote:

From what I remember, gcc always does a shallow copy (case 1) and as an
optimization, it implements copy-on-write.

Basically, assigning a[0] = t will have t and a[0] pointed to the same
location till you change either t or a[0]. 

Sorry to put it so bluntly - but this is total nonsense. Where did pointers 
come in? 

Structure assignment is very much a part of the C standard at least since c99. 
In the "Constraints" part of the section titled "Simple Assignment" (Section 
6.5.16.1) , we are told it is valid to have "the left operand has a qualified 
or unqualified version of a structure or union type compatible with the type of 
the right". The sematics of the copy is as you would expect it - a field to 
field copy; padding bits if any need not be copied.

-Karra

Other related posts: