Table of Contents
The typedef
keyword is used to declare an identifier as an alias for an existing type. Like all D type declarations, the typedef
keyword is used outside probe clauses in a declaration of the form:
typedefexisting-type
new-type
;
where existing-type
is any type declaration and new-type
is an identifier to be used as the alias for this type. For example, the declaration:
typedef unsigned char uint8_t;
is used internally by the D compiler to create the uint8_t
type alias. Type aliases can be used anywhere that a normal type can be used, such as the type of a variable or associative array value or tuple member. You can also combine typedef
with more elaborate declarations such as the definition of a new struct
:
typedef struct foo { int x; int y; } foo_t;
In this example, struct foo
is defined as the same type as its alias, foo_t
. Solaris C system headers often use the suffix _t
to denote a typedef
alias.