typedef                  Derived Data Type Specifier
 
    The typedef keyword is used to invent a synonym for a type. This is
    useful for two purposes: to give a type a name that is more
    meaningful than one of C's basic types, and to give a name to a
    complex type declaration (so you need not keep reading and writing
    that complex type).  The format of a typedef is:
 
            typedef type declarator [[, declarator] ... ] ;
 
      Notes:    Many people don't use typedef--they use #define instead,
                since it can achieve the same result. However, there are
                many type declarations in which #define cannot be used in
                place of typedef. The point to remember is that typedef
                is part of the C language and it is processed by the
                compiler, which knows about types--typedef was
                specifically designed to give synonyms to types.
                #define, on the other hand, is part of the preprocessor,
                which knows nothing about C types--it merely provides a
                string substitution facility and should be restricted to
                naming macros.
 
  -------------------------------- Example ---------------------------------
 
           typedef register fast;
           typedef char *string;
           typedef struct {double real, imag;} complex;
           typedef struct link *FNODE();
 
           fast total;
           string name, state;
           complex value;
           FNODE getnode;
 
            /*  In this last example, it is not immediately obvious that
                getnode is a function, since that property is hidden in
                the typedef, which is typically placed in a header.
                Therefore, the synonym should probably be defined as:  */
 
           typedef struct link *NODE; NODE getnode();

Seealso:



This page last updated on Fri Nov 30 10:48:32 MSK 2001
Copyright © 1992-2001, Vitaly Filatov, Moscow, Russia
Webmaster