Thread: typedefs in C language

  1. #1
    Registered User
    Join Date
    Mar 2007
    Posts
    25

    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

  2. #2
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,005
    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 {.
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  3. #3
    Registered User
    Join Date
    Mar 2007
    Posts
    25
    thanks for your repy....

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. What language did they make Java in?
    By jverkoey in forum A Brief History of Cprogramming.com
    Replies: 17
    Last Post: 07-03-2005, 04:18 PM
  2. Strange loop
    By D@rk_force in forum C++ Programming
    Replies: 22
    Last Post: 12-18-2004, 02:40 PM
  3. assembly language...the best tool for game programming?
    By silk.odyssey in forum Game Programming
    Replies: 50
    Last Post: 06-22-2004, 01:11 PM
  4. Language of choice after C++
    By gandalf_bar in forum A Brief History of Cprogramming.com
    Replies: 47
    Last Post: 06-15-2004, 01:20 AM
  5. Language Script..
    By vasanth in forum A Brief History of Cprogramming.com
    Replies: 12
    Last Post: 03-30-2003, 06:48 AM