Thursday, 16 April 2015

Difference between typedef enum and only enum

module top();

  // create a data-type called on_off_e which is derived from enum type
  typedef enum bit {OFF, ON} on_off_e;
  // create a variable of enum
  enum bit {CLOSE, OPEN} switch_e;

  // create a variable of data-type on_off_e
  on_off_e on_off;

  // If you try to define variable of switch_e then tool will give compilation error because switch_e it self is a variable
  //switch_e switch_val;

    $display("on_off=%s, on_off=%b",, on_off);
    $display("switch_e=%s, switch_e=%b",, switch_e);

endmodule : top

on_off=OFF, on_off=0
switch_e=CLOSE, switch_e=0

No comments:

Post a Comment