943,923 Members | Top Members by Rank

Ad:
  • C Discussion Thread
  • Unsolved
  • Views: 1795
  • C RSS
Oct 9th, 2005
0

monolithic copying

Expand Post »
When a structure is assigned, passed, or returned, the copying is done monolithically....what does this monolithic mean
any example??
Similar Threads
SpS
Reputation Points: 70
Solved Threads: 32
Posting Pro
SpS is offline Offline
598 posts
since Aug 2005
Oct 9th, 2005
0

Re: monolithic copying

Quote 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. }
Team Colleague
Reputation Points: 1135
Solved Threads: 172
Super Senior Demiposter
Rashakil Fol is offline Offline
2,478 posts
since Jun 2005
Oct 9th, 2005
0

Re: monolithic copying

What about pointers...anything pointed by pointers???.....if possible by example
SpS
Reputation Points: 70
Solved Threads: 32
Posting Pro
SpS is offline Offline
598 posts
since Aug 2005
Oct 9th, 2005
0

Re: monolithic copying

Quote 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.
Team Colleague
Reputation Points: 1135
Solved Threads: 172
Super Senior Demiposter
Rashakil Fol is offline Offline
2,478 posts
since Jun 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C Forum Timeline: C Sockets
Next Thread in C Forum Timeline: type conversion





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC