Translations of this page?:

typedef

Syntax:

    typedef existing-type new-type;

The typedef keyword allows you to create a new alias for an existing data type. This is often useful if you find yourself using a unwieldy data type – you can use typedef to create a shorter, easier-to-use name for that data type. For example:

    typedef unsigned int* pui_t;
 
    // data1 and data2 have the same type
    pui_t data1;
    unsigned int* data2;

The syntax above is a simplification. More generally, after the word “typedef”, the syntax looks exactly like what you would do to declare a variable of the existing type with the variable name of the new type name. Therefore, for more complicated types, the new type name might be in the middle of the syntax for the existing type. For example:

    typedef char (*pa)[3]; // "pa" is now a type for a pointer to an array of 3 chars
    typedef int (*pf)(float); // "pf" is now a type for a pointer to a function which takes 1 float argument and returns an int
 
• • • IndexRecent changesRSScc