home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #1 / NN_1993_1.iso / spool / comp / lang / c / 19548 < prev    next >
Encoding:
Text File  |  1993-01-11  |  1.4 KB  |  51 lines

  1. Path: sparky!uunet!cis.ohio-state.edu!zaphod.mps.ohio-state.edu!howland.reston.ans.net!usc!cs.utexas.edu!sun-barr!olivea!gossip.pyramid.com!pyramid!infmx!johnl
  2. From: johnl@informix.com (Jonathan Leffler)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: struct vs. typedef
  5. Message-ID: <1993Jan11.170937.22822@informix.com>
  6. Date: 11 Jan 93 17:09:37 GMT
  7. References: <uRL4wB7w165w@cybrspc.uucp> <JAR.93Jan10152829@solva.ifi.uio.no>
  8. Sender: news@informix.com (Usenet News)
  9. Organization: Informix Software, Inc.
  10. Lines: 39
  11.  
  12. In article <JAR.93Jan10152829@solva.ifi.uio.no> jar@solva.ifi.uio.no (Jo Are Rosland) writes:
  13. >In article <uRL4wB7w165w@cybrspc.uucp> Roy M. Silvernail writes:
  14. >
  15. >   typedef struct n {
  16. >       int x,y;
  17. >       struct n *last,*next, *up, *down;
  18. >       void (*show)(struct n *);
  19. >       int width;
  20. >       void **value;
  21. >   } ITEM;
  22. >
  23. >   Now, this works, but it sure seems clumsy.  Is this really the only way
  24. >   to do this type of construct?  If not, is it the optimal solution, or is
  25. >   there some extremely clever trick I'm missing?
  26. >
  27. >Given C, that's the best you can get.  You'll just have to get used to
  28. >it, just like the rest of us :-).
  29.  
  30. Not so:
  31.  
  32. typedef struct n ITEM;
  33. struct n {
  34.        int x,y;
  35.        ITEM *last,*next, *up, *down;
  36.        void (*show)(ITEM *);
  37.        int width;
  38.        void **value;
  39. };
  40.  
  41. I prefer the style:
  42.  
  43. typedef struct Tag Tag;
  44. struct Tag
  45. {
  46.     ...
  47. };
  48.  
  49. where the structure tag and the typdef name are the same -- it gets closer to
  50. C++ that way.
  51.