typedef

suggest change

typedef declares an alias for an existing type. It does not create a distinct type. Its syntax mirrors a variable declaration.

/* Byte can be used wherever `unsigned char` is needed */
typedef unsigned char Byte;

/* Integer is the type used to declare an array consisting of a single int */
typedef int Integer[1];

/* NodeRef is a type used for pointers to a structure type with the tag "node" */
typedef struct node *NodeRef;

/* SigHandler is the function pointer type that gets passed to the signal function. */
typedef void (*SigHandler)(int);

The standard classifies typedef as a storage-class specifier, but it does not reserve storage. It cannot be combined with static, extern, or the other storage-class specifiers.

A typedef is not the same thing as a #define. For one declarator the following both produce a pointer:

typedef int newType;
newType *ptr; /* pointer to int */
#define newType int
newType *ptr; /* also a pointer to int */

The difference shows up when one macro replacement is a pointer type and several declarators share it:

typedef int *newType;
newType a, b; /* both are int * */
#define newType int *
newType a, b; /* int *a, b; only a is a pointer */

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents