home *** CD-ROM | disk | FTP | other *** search
- 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
- From: johnl@informix.com (Jonathan Leffler)
- Newsgroups: comp.lang.c
- Subject: Re: struct vs. typedef
- Message-ID: <1993Jan11.170937.22822@informix.com>
- Date: 11 Jan 93 17:09:37 GMT
- References: <uRL4wB7w165w@cybrspc.uucp> <JAR.93Jan10152829@solva.ifi.uio.no>
- Sender: news@informix.com (Usenet News)
- Organization: Informix Software, Inc.
- Lines: 39
-
- In article <JAR.93Jan10152829@solva.ifi.uio.no> jar@solva.ifi.uio.no (Jo Are Rosland) writes:
- >In article <uRL4wB7w165w@cybrspc.uucp> Roy M. Silvernail writes:
- >
- > 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?
- >
- >Given C, that's the best you can get. You'll just have to get used to
- >it, just like the rest of us :-).
-
- Not so:
-
- typedef struct n ITEM;
- struct n {
- int x,y;
- ITEM *last,*next, *up, *down;
- void (*show)(ITEM *);
- int width;
- void **value;
- };
-
- I prefer the style:
-
- typedef struct Tag Tag;
- struct Tag
- {
- ...
- };
-
- where the structure tag and the typdef name are the same -- it gets closer to
- C++ that way.
-