-
typedefs in C language
I have a doubt regarding typedefs in C
lets take an example
Code:
typedef struct{
int i;
}test;
int main()
{
struct test_t t; //copiler gives error
test t; //no error message
}
As far I know typedef gives the name test to the structure then why we cannot
use it as struct test, even though we need not to use as struct test after declaring as typedef.
please comment
thanks & regards
onebrother
-
You've got an anonymous struct aliased as test; there is no struct test_t. Since there is no struct test_t, the compiler rightly complains.
If you want to name the structure that goes between the struct keyword and the {.
-