In complex testbenches some variable declarations might have a longer data-type specification or require to be used in multiple places in the testbench. In such cases we can use a typedef to give a user-defined name to an existing data type. The new data-type can then be used throughout the code and hence avoids the need to edit in multiple places if required.

  // Normal declaration
  unsigned shortint my_data;
  enum {RED, YELLOW, GREEN} e_light;
  bit [7:0] my_byte;
  // u_shorti and e_light are two new data-types 
  typedef unsigned shortint u_shorti;
  typedef enum {RED, YELLOW, GREEN} e_light;
  typedef bit [7:0] ubyte;
  // Use these new data-types to create variables
  u_shorti    my_data;
  e_light     light1;
  ubyte       my_byte;
  typedef data_type type_name [range];

Was this article helpful ?