When someone declaring typedef struct...
Code:typedef struct _MyType //What is this for? { //... } MyType, *PMyType;
When someone declaring typedef struct...
Code:typedef struct _MyType //What is this for? { //... } MyType, *PMyType;
So that they can write MyType instead of struct MyType.
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
Actually the can write _Mytype instead of struct _Mytype.
MyType and *PMyType are variable declarations
No, this is C, not C++.Actually the can write _Mytpe instead of struct _Mtype.
No, because of the typedef keyword. MyType is a typedef for struct _Mytype, PMyType is a typedef for struct _MyType*.MyType and *PMyType are variable declarations
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
Personnaly, from what I understand of your question, someone would write something like
because it's the only way for a struct to contain a pointer on itself; exampleCode:typedef struct _MyType //What is this for? { //... } MyType, *PMyType;
Code:typedef struct _MyType //What is this for? { struct _MyType *next; MyType *next; // Wouldn't work since MyType is not known at this point } MyType, *PMyType;
I hate real numbers.
hmm... foxman appears to have interpreted the question more accurately than I have, and if that was indeed your intention, audinue, then I would say that foxman's answer is correct.
Incidentally, note that C99 section 7.1.3 states that "all identifiers that begin with an underscore and either an uppercase letter or another underscore are always reserved for any use", so by right one should not use _MyType as a type name unless one is writing the implementation of the core language or the standard library.
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
Thanks foxman!
Is my English bad T_T??hmm... foxman appears to have interpreted the question more accurately than I have
Last edited by audinue; 06-22-2008 at 10:45 AM.
No, but you could have elaborated by asking "why do we need to provide a type name at this point when we are already providing a type name with the typedef?"Is my English bad T_T??
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
That's a long one But, sorry for my undescriptive question.No, but you could have elaborated by asking "why do we need to provide a type name at this point when we are already providing a type name with the typedef?"