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

  1. Path: sparky!uunet!wupost!uwm.edu!spool.mu.edu!umn.edu!cybrspc!roy
  2. From: roy%cybrspc@cs.umn.edu (Roy M. Silvernail)
  3. Newsgroups: comp.lang.c
  4. Subject: struct vs. typedef
  5. Message-ID: <uRL4wB7w165w@cybrspc.uucp>
  6. Date: Sat, 09 Jan 93 01:10:17 CST
  7. Organization: Villa CyberSpace, Minneapolis, MN
  8. Lines: 43
  9.  
  10. In a current project, I have a structure that looks like
  11.  
  12. struct n {
  13.     int x,y;
  14.     struct n *last,*next, *up, *down;
  15.     void (*show)(struct n *);
  16.     int width;
  17.     void **value;
  18. };
  19.  
  20. No problem, you say... But I wanted to convert it to a typedef, to
  21. simplify another struct (which has about 30 instances of this one), so
  22. I tried
  23.  
  24. typedef struct {
  25.     int x,y;
  26.     ITEM *last,*next, *up, *down;
  27.     void (*show)(ITEM *);
  28.     int width;
  29.     void **value;
  30. } ITEM;
  31.  
  32. and my compiler barfs on the included ITEMs.  OK, off to the manual,
  33. which sort of explains things, along with mentioning that typedefs and
  34. structure tags are rarely, if ever, needed simultaneously.
  35. Nevertheless, I ended up with
  36.  
  37. typedef struct n {
  38.     int x,y;
  39.     struct n *last,*next, *up, *down;
  40.     void (*show)(struct n *);
  41.     int width;
  42.     void **value;
  43. } ITEM;
  44.  
  45. Now, this works, but it sure seems clumsy.  Is this really the only way
  46. to do this type of construct?  If not, is it the optimal solution, or is
  47. there some extremely clever trick I'm missing?
  48. --
  49. Roy M. Silvernail --  roy%cybrspc@cs.umn.edu - OR-  cybrspc!roy@cs.umn.edu
  50.   perl -e '$x = 1/20; print "Just my \$$x! (adjusted for inflation)\n"'
  51.           "Does that not fit in with your plans?"
  52.                       -- Mr Wiggen, of Ironside and Malone (Monty Python)
  53.