home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / comp / std / cplus / 2126 < prev    next >
Encoding:
Internet Message Format  |  1993-01-27  |  1.3 KB

  1. Path: sparky!uunet!europa.eng.gtefsd.com!emory!swrinde!sdd.hp.com!usc!howland.reston.ans.net!bogus.sura.net!darwin.sura.net!ukma!cs.widener.edu!dsinc!ub!galileo.cc.rochester.edu!rochester!rit!cci632!dwr
  2. From: dwr@cci632.cci.com (Donald W. Rouse II)
  3. Newsgroups: comp.std.c++
  4. Subject: Re: structs that define nothing
  5. Message-ID: <1993Jan27.173319.15550@cci632.cci.com>
  6. Date: 27 Jan 93 17:33:19 GMT
  7. References: <1993Jan25.171222.1@fnalng.fnal.gov>
  8. Organization: [Computer Consoles, Inc., Rochester, NY
  9. Lines: 34
  10.  
  11. In article <1993Jan25.171222.1@fnalng.fnal.gov> b91926@fnalng.fnal.gov writes:
  12. >Does the c++ standard have anything to say about the legality of a
  13. >construct like the following:
  14. >
  15. >...
  16. >struct
  17. >{
  18. >  int a;
  19. >  int b;
  20. >};
  21. >
  22. >...
  23. >
  24. >Such an example appeared in a recent issue of "C++ Report". The
  25. >problem with this code is that it defines absolutely nothing.
  26.  
  27. This example reminds me of a possible extension to C++ (and C)
  28. that could occasionally be useful: anonymous structures,
  29. which are analogous to anonymous unions.
  30.  
  31. Example:
  32.     typedef union
  33.         {
  34.         unsigned long lw;
  35.         struct { unsigned short sw0, sw1; };
  36.         struct { unsigned char b0, b1, b2, b3; };
  37.         }    machword;
  38.     machword    r1, r2;
  39.  
  40. Now you can access r1.b2, instead of having to do
  41. something like r1.b.b2, etc.
  42.  
  43. Note that the only place this would be useful
  44. is inside a union.
  45.