A typedef declaration lets you define your own identifiers that can be used in place of type specifiers such as int, byte, real. Let us see an example of creating data type "nibble".
typedefbit[3:0] nibble; // Defining nibble data type.
nibble a, b; // a and b are variables with nibble data types.
Advantages Of Using Typedef :
Shorter names are easier to type and reduce typing errors.
Improves readability by shortening complex declarations.
Improves understanding by clarifying the meaning of data.
Changing a data type in one place is easier than changing all of its uses throughout the code.
Allows defining new data types using structs, unions and Enumerations also.
Increases reusability.
Useful is type casting.
Example of typedef using struct, union and enum data types.
typedefenum {NO, YES} boolean;
typedefunion { int i; shortreal f; } num; // named union type
typedefstruct {
bit isfloat;
union { int i; shortreal f; } n; // anonymous type
} tagged_st; // named structure
boolean myvar; // Enum type variable
num n; // Union type variable
tagged_st a[9:0]; // array of structures