"typedef" to create user types

Home Forums C-programming.. "typedef" to create user types

Viewing 1 post (of 1 total)
  • Author
    Posts
  • #2234 Reply
    Humble
    Keymaster

    “typedef” is a keyword which can be used to give an alias/symbolic name to “types” .. That said, simplification is one of the best use case of typedef usage..

    For ex: from standard header ..

    typedef struct
      {
        int quot;                   /* Quotient.  */
        int rem;                    /* Remainder.  */
      } div_t;
    
    
    
    
    
    Then you can use 'div_t' for rest of your type variables. 
    
    typedef is a compile time stuff.. You can compare 'typedef' with "#defines" ..but there are differences ..
    
    *) typedefs are bound to scoping rules where #defines are not.. #defines are valid till end of file or corresponding #undef.
    
    *) As mentioned above, typedefs are compiler stuff where #defines are preprocessor.
    
    *) for alias definitions on pointer types its better to use typedefs than #defines.
    
    
Viewing 1 post (of 1 total)
Reply To: "typedef" to create user types
Your information: