CHAPTER 11

image

Typedef

An alias for a type can be created using the typedef keyword followed by the type and alias name. By convention, uppercase letters are commonly used for these definitions.

typedef unsigned char BYTE;

Once defined, the alias can be used as a synonym for its specified type.

BYTE b; /* unsigned char */

typedef does not only work for existing types, but can also include a definition of a user-defined type – such as a struct, union, or enum. This can make a complex type easier to understand.

typedef struct { int points; } score;score a, b, c;a.points = 10;

If used properly a type alias can simplify a long or confusing type name, ...

Get C Quick Syntax Reference now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.