home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #1 / NN_1993_1.iso / spool / comp / std / c / 3351 < prev    next >
Encoding:
Internet Message Format  |  1993-01-10  |  1.8 KB

  1. Path: sparky!uunet!zaphod.mps.ohio-state.edu!howland.reston.ans.net!bogus.sura.net!darwin.sura.net!gatech!enterpoop.mit.edu!world!ksr!jfw
  2. From: jfw@ksr.com (John F. Woods)
  3. Newsgroups: comp.std.c
  4. Subject: Re: Struct hack one last time (one last time)
  5. Message-ID: <20822@ksr.com>
  6. Date: 10 Jan 93 17:09:32 EST
  7. References: <1993Jan7.221207.13818@leland.Stanford.EDU> <1375@mwtech.UUCP>
  8. Sender: news@ksr.com
  9. Lines: 35
  10.  
  11. martin@mwtech.UUCP (Martin Weitzel) writes:
  12. >Which directly brings up the question if (or if not) for
  13. >any modifiable lvalue `x' and some `y' of the same type an
  14. >assignment
  15. >            x = y;
  16. >may behave differently
  17. >as a bitwise copy
  18. >            memcpy(&x, &y, sizeof x);
  19.  
  20. >(For the pedantics: Assume the appropriate header is included
  21. >and the two objects do not overlap.)
  22.  
  23. >To put it into the language of the standard: May some (otherwise
  24. >strictly conforming) program change its behavior if the above
  25. >two were switched.
  26.  
  27. This has a definite answer:  a conforming implementation may have
  28.     x = y;
  29. behave differently from
  30.     memcpy(&x, &y, sizeof(x));
  31.  
  32. If x and y are structure types, it is already settled (via a Request For
  33. Interpretation, I believe) that holes in a structure need not be copied
  34. by assignment; this could be exposed in an otherwise conforming program
  35. by
  36.     memcmp(&x, &y, sizeof(x))
  37.  
  38. Another example (which is what I started with, until I remembered this
  39. clear example) would be pointers; I believe that there is no requirement
  40. that a pointer to an object have a unique representation, only that all
  41. pointers to the same object shall *compare* equal.  In particular, segmentation
  42. and alignment concerns could cause there to be a preferred representation
  43. for a pointer (which could be enforced at assignment) but several possible
  44. ways to represent the same pointer (which might get calculated differently
  45. for different expressions, depending on the compiler's expedience).
  46.