home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!wupost!uwm.edu!spool.mu.edu!umn.edu!cybrspc!roy
- From: roy%cybrspc@cs.umn.edu (Roy M. Silvernail)
- Newsgroups: comp.lang.c
- Subject: struct vs. typedef
- Message-ID: <uRL4wB7w165w@cybrspc.uucp>
- Date: Sat, 09 Jan 93 01:10:17 CST
- Organization: Villa CyberSpace, Minneapolis, MN
- Lines: 43
-
- In a current project, I have a structure that looks like
-
- struct n {
- int x,y;
- struct n *last,*next, *up, *down;
- void (*show)(struct n *);
- int width;
- void **value;
- };
-
- No problem, you say... But I wanted to convert it to a typedef, to
- simplify another struct (which has about 30 instances of this one), so
- I tried
-
- typedef struct {
- int x,y;
- ITEM *last,*next, *up, *down;
- void (*show)(ITEM *);
- int width;
- void **value;
- } ITEM;
-
- and my compiler barfs on the included ITEMs. OK, off to the manual,
- which sort of explains things, along with mentioning that typedefs and
- structure tags are rarely, if ever, needed simultaneously.
- Nevertheless, I ended up with
-
- typedef struct n {
- int x,y;
- struct n *last,*next, *up, *down;
- void (*show)(struct n *);
- int width;
- void **value;
- } ITEM;
-
- Now, this works, but it sure seems clumsy. Is this really the only way
- to do this type of construct? If not, is it the optimal solution, or is
- there some extremely clever trick I'm missing?
- --
- Roy M. Silvernail -- roy%cybrspc@cs.umn.edu - OR- cybrspc!roy@cs.umn.edu
- perl -e '$x = 1/20; print "Just my \$$x! (adjusted for inflation)\n"'
- "Does that not fit in with your plans?"
- -- Mr Wiggen, of Ironside and Malone (Monty Python)
-