Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > C Moderated > Re: typedef a s...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 3 of 4 Topic 1079 of 1133
Post > Topic >>

Re: typedef a struct

by =?utf-8?Q?Dag-Erling_Sm=C3=B8rgrav?= <des@[EMAIL PROTECTED] > Apr 18, 2008 at 04:11 PM

Taras_96 <taras.di@[EMAIL PROTECTED]
> writes:
> You can typedef a struct by using the following
>
> typedef struct x {} X, *PX;
>
> Now, I can understand the use of the typedefs, X and PX. They allow
> you to declare the structs without having to use the struct keyword.
> However, I'm not quite sure of the usefullness of the struct tag 'x'.

It allows you to declare (not define) struct x in other places where the
typedef is not visible.  You won't be able to use struct x directly, but
you will be able to use pointers to objects of type struct x.

If that is not an issue in your code (e.g. a short program consisting of
a single compilation unit), you can drop the struct tag.

(it also allows you to refer to struct x within itself, e.g. if struct x
is intended to be an element in a linked list or a node in a tree, but
struct x in your example is empty...)

DES
-- 
Dag-Erling Smørgrav - des@[EMAIL PROTECTED]
 
comp.lang.c.moderated - moderation address: clcm@[EMAIL PROTECTED]
 -- you must
have an appropriate newsgroups line in your header for your mail to be
seen,
or the newsgroup name in square brackets in the subject line.  Sorry.
 




 4 Posts in Topic:
typedef a struct
Taras_96 <taras.di@[EM  2008-04-16 16:56:29 
Re: typedef a struct
Kenneth Brody <kenbrod  2008-04-18 16:11:33 
Re: typedef a struct
=?utf-8?Q?Dag-Erling_Sm=C  2008-04-18 16:11:41 
Re: typedef a struct
Taras_96 <taras.di@[EM  2008-04-21 13:18:40 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Thu Jul 24 16:03:50 CDT 2008.