home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / std / c / 2565 < prev    next >
Encoding:
Text File  |  1992-09-03  |  1.1 KB  |  40 lines

  1. Newsgroups: comp.std.c
  2. From: jes@grendel.demon.co.uk (Jim Segrave)
  3. Path: sparky!uunet!pipex!demon!grendel.demon.co.uk!jes
  4. Distribution: world
  5. Subject: How is struct assignment defined (idle query)?
  6. X-Mailer: cppnews $Revision: 1.14 $
  7. Organization: None
  8. Lines: 27
  9. Date: Thu, 3 Sep 1992 12:13:26 +0000
  10. Message-ID: <715547606snx@grendel.demon.co.uk>
  11. Sender: usenet@gate.demon.co.uk
  12.  
  13.  
  14. I don't have access to a copy of the ANSI spec, hence my query:
  15.  
  16. Does ANSI say that structure assignment is done by member-wise copy or
  17. by bit-wise copying?
  18. The reason I ask is that if it is a bit-wise copy, then any padding in
  19. a struct would have to have some (presumably inplementation defined)
  20. value written to it so that the padding bytes could be copied.
  21. I realise that most implementations will not suffer any ill effects
  22. from the notional conversion of the following assignment:
  23.  
  24. struct a {...} a_one = { ...};
  25. int some_func ()
  26. {
  27.   struct a a_two = a_one;
  28.  
  29.  
  30. to:
  31.   memcpy ((void *) &a_two, (void *) &a_one, sizeof (struct a));
  32.  
  33. but I wondered if this conveys the actual ANSI definition of struct
  34. assignment.
  35.  
  36.  
  37. --
  38. Jim Segrave
  39.  
  40.