home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #1 / NN_1993_1.iso / spool / comp / std / c / 3346 < prev    next >
Encoding:
Text File  |  1993-01-08  |  2.0 KB  |  54 lines

  1. Newsgroups: comp.std.c
  2. Path: sparky!uunet!taumet!steve
  3. From: steve@taumet.com (Steve Clamage)
  4. Subject: Re: Struct hack one last time (one last time)
  5. Message-ID: <1993Jan8.190840.11087@taumet.com>
  6. Organization: TauMetric Corporation
  7. References: <1993Jan7.221207.13818@leland.Stanford.EDU> <1993Jan8.065947.29719@sq.sq.com>
  8. Date: Fri, 8 Jan 1993 19:08:40 GMT
  9. Lines: 43
  10.  
  11. msb@sq.sq.com (Mark Brader) writes:
  12.  
  13. >In particular, it could not modify padding at the end of a struct,
  14. >precisely *because* it would break the struct hack.
  15.  
  16. We seem to have some circular reasoning here.
  17.  
  18. I proposed an implemention which I claimed was conforming on which
  19. the struct hack would not work; therefore the struct hack is illegal.
  20.  
  21. Mark claims the struct hack is legal; therefore the proposed
  22. implementation is not conforming.
  23.  
  24. I think we need to show that the proposed implementation is non-
  25. conforming or that the the struct hack is not strictly-conforming by
  26. appealing to the language of the standard.
  27.  
  28. I remain unconvinced that the struct hack is strictly conforming,
  29. completely apart from the possibly flakey implementation I proposed.
  30.  
  31. For example, if the struct hack is strictly conforming, what about this:
  32.  
  33.     struct S {
  34.         double a[2];
  35.         double b;
  36.     } s;
  37.     s.a[2] = 1.0;
  38.  
  39. The array reference exceeds the declared bounds of s.a, but not the
  40. bounds of object s, because sizeof(s) can't be smaller than
  41. sizeof(a)+sizeof(b).  If a compiler can't add padding to the end of
  42. the struct for other than alignment, then surely it can't add padding
  43. between a and b, because it can't be required for alignment.  Therefore
  44. s.a[2] must be the same as s.b.
  45.  
  46. I don't buy this reasoning, and it seems to me it is no different
  47. from the struct hack.  I claim that both this example and the
  48. struct hack are not strictly conforming, because the declared bounds
  49. of an array are exceeded.  Probably both examples will work on any
  50. typical implementation, however, which is a separate issue.
  51. -- 
  52.  
  53. Steve Clamage, TauMetric Corp, steve@taumet.com
  54.