home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #20 / NN_1992_20.iso / spool / comp / std / c / 2592 < prev    next >
Encoding:
Text File  |  1992-09-08  |  1.8 KB  |  41 lines

  1. Path: sparky!uunet!olivea!spool.mu.edu!wupost!usc!zaphod.mps.ohio-state.edu!cis.ohio-state.edu!ucbvax!jit081.enet.dec.com!diamond
  2. From: diamond@jit081.enet.dec.com (09-Sep-1992 1034)
  3. Newsgroups: comp.std.c
  4. Subject: Re: Zero-length structures and pointer comparisons
  5. Message-ID: <9209090135.AA00853@enet-gw.pa.dec.com>
  6. Date: 9 Sep 92 01:35:05 GMT
  7. Sender: daemon@ucbvax.BERKELEY.EDU
  8. Lines: 31
  9.  
  10. In article <9225302.22791@mulga.cs.mu.OZ.AU> fjh@munta.cs.mu.OZ.AU (Fergus James HENDERSON) writes:
  11. >First, a question for comp.std.c:
  12. >is the following a legal (strictly conforming) program?
  13. >       struct S { unsigned:0; }
  14. >       int main() { return sizeof(S); }
  15.  
  16. No.  ANSI C section 3.5.2.1, page 61 lines 25 to 26:  "If the
  17. struct-declaration-list contains no named members, the behavior is undefined."
  18.  
  19. >Secondly, some comments about C++.
  20. >In ANSI C, pointer comparisons between pointers to unrelated objects (ie.
  21. >objects that are not both members of the same aggregate) cause undefined
  22. >behavior, I believe. For example, the following program
  23. >       #include <assert.h>
  24. >       int main() {
  25. >               int x,y;
  26. >               assert(&x != &y);
  27. >       }
  28. >should cause undefined behavior. [Is this correct?]
  29.  
  30. No.  For relational operators (<, >, <=, >=) that would be correct.
  31. For equality operators (==, !=) the result is defined.  Comparing whether
  32. a pointer is equal to a null pointer or not is a common operation, and
  33. (unless miscoded in some other way) is defined.
  34.  
  35. I don't have modern documents on C++ and don't dare to answer your later
  36. questions.  For the same reason, this answer is not cross-posted.
  37. --
  38. Norman Diamond       diamond@jit081.enet.dec.com
  39. If this were the company's opinion, I wouldn't be allowed to post it.
  40. "Yeah -- bad wiring.  That was probably it.  Very bad."
  41.