monolithic copying

Reply

Join Date: Aug 2005
Posts: 598
Reputation: SpS is on a distinguished road 
Solved Threads: 32
SpS's Avatar
SpS SpS is offline Offline
Posting Pro

monolithic copying

 
0
  #1
Oct 9th, 2005
When a structure is assigned, passed, or returned, the copying is done monolithically....what does this monolithic mean
any example??
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 2,078
Reputation: Rashakil Fol is just really nice Rashakil Fol is just really nice Rashakil Fol is just really nice Rashakil Fol is just really nice 
Solved Threads: 142
Team Colleague
Rashakil Fol's Avatar
Rashakil Fol Rashakil Fol is offline Offline
Super Senior Demiposter

Re: monolithic copying

 
0
  #2
Oct 9th, 2005
Originally Posted by sunnypalsingh
When a structure is assigned, passed, or returned, the copying is done monolithically....what does this monolithic mean
any example??
It means that every member variable gets copied over.

For example, this C code:

  1. #include <stdio.h>
  2.  
  3. struct cat {
  4. int id_num;
  5. int age;
  6. int HP;
  7. int MP;
  8. };
  9.  
  10. int main(void) {
  11.  
  12. struct cat x;
  13. struct cat y;
  14.  
  15. x.id_num = 1; x.age = 2; x.HP = 3; x.MP = 4;
  16.  
  17. y = x;
  18.  
  19. /* Now y.id_num == 1, y.age == 2, ... */
  20.  
  21. printf("%d %d %d %d\n", y.id_num, y.age, y.HP, y.MP);
  22. /* Prints "1 2 3 4\n" */
  23.  
  24. return 0;
  25. }
All my posts may be redistributed under the GNU Free Documentation License.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 598
Reputation: SpS is on a distinguished road 
Solved Threads: 32
SpS's Avatar
SpS SpS is offline Offline
Posting Pro

Re: monolithic copying

 
0
  #3
Oct 9th, 2005
What about pointers...anything pointed by pointers???.....if possible by example
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 2,078
Reputation: Rashakil Fol is just really nice Rashakil Fol is just really nice Rashakil Fol is just really nice Rashakil Fol is just really nice 
Solved Threads: 142
Team Colleague
Rashakil Fol's Avatar
Rashakil Fol Rashakil Fol is offline Offline
Super Senior Demiposter

Re: monolithic copying

 
0
  #4
Oct 9th, 2005
Originally Posted by sunnypalsingh
What about pointers...anything pointed by pointers???.....if possible by example
Consider a structure of the form

  1. struct dog {
  2. type_1 val_1;
  3. type_2 val_2;
  4. type_3 val_3;
  5. .
  6. .
  7. .
  8. type_n val_n;
  9. };

The expression "x = y;", where x and y are of type struct dog, could be written as the following:

  1. x.val_1 = y.val_1;
  2. x.val_2 = y.val_2;
  3. x.val_3 = y.val_3;
  4. .
  5. .
  6. .
  7. x.val_n = y.val_n;

So pointers would get copied, yes. They would contain the same memory address.




Remember that in C++ (but not C), structures can have copy constructors, which change this.
All my posts may be redistributed under the GNU Free Documentation License.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C Forum


Views: 1745 | Replies: 3
Thread Tools Search this Thread



Tag cloud for C
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2010 DaniWeb® LLC