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

  1. Newsgroups: comp.lang.c
  2. Path: sparky!uunet!usc!howland.reston.ans.net!wupost!crcnis1.unl.edu!moe.ksu.ksu.edu!engr.uark.edu!wdraper.uark.edu!wrd
  3. From: wrd@wdraper.uark.edu (William R. Draper)
  4. Subject: Re: struct vs. typedef
  5. Message-ID: <1993Jan11.162844.6013@wdraper.uark.edu>
  6. Sender: netnews@engr.uark.edu (NetNews Administrator)
  7. Nntp-Posting-Host: wdraper.uark.edu
  8. Organization: University of Arkansas
  9. References: <uRL4wB7w165w@cybrspc.uucp> <JAR.93Jan10152829@solva.ifi.uio.no>
  10. Date: Mon, 11 Jan 1993 16:28:44 GMT
  11. Lines: 37
  12.  
  13. jar@solva.ifi.uio.no (Jo Are Rosland) writes:
  14.  
  15. >In article <uRL4wB7w165w@cybrspc.uucp> Roy M. Silvernail writes:
  16. >
  17. >   typedef struct n {
  18. >       int x,y;
  19. >       struct n *last,*next, *up, *down;
  20. >       void (*show)(struct n *);
  21. >       int width;
  22. >       void **value;
  23. >   } ITEM;
  24. >
  25. >   Now, this works, but it sure seems clumsy.  Is this really the only way
  26. >   to do this type of construct?  If not, is it the optimal solution, or is
  27. >   there some extremely clever trick I'm missing?
  28. >
  29. >Given C, that's the best you can get.  You'll just have to get used to
  30. >it, just like the rest of us :-).
  31. >
  32.  
  33. If you would rather, you can try:
  34.  
  35. typedef struct n *ITEMPTR;
  36. typedef struct n {
  37.    int x, y;
  38.    ITEMPTR last, next, up, down;
  39.    void (*show)(ITEMPTR);
  40.    int width;
  41.    void **value;
  42.    } ITEM;
  43.  
  44. I usually define it as Silvernail has, but where you have several
  45. instances of a pointer, it may be easier to define the pointer first.
  46.  
  47. Bill
  48.  
  49. email: wrd@engr.uark.edu
  50.