quick.gif

space2.gif

space2.gif

space2.gif

space2.gif

space2.gif

space2.gif

space2.gif

   

space.gif

   

space.gif

  ../images/main/bulllet_4dots_orange.gif User defined types

User defined types are same as that found in other programming language and same as found in C language. Using this, a user can define his own data types. A type can be used before it is defined, provided it is first identified as a type by an empty typedef:

   

space.gif

Syntax

   

space.gif

  • typedef data_type type_identifier variable_dimension
  • typedef interface_instance_identifier . type_identifier;
  • typedef [ enum | struct | union | class ] type_identifier ;
   

space.gif

Sometimes a user defined type needs to be declared before the contents of the type has been defined. This is of use with user defined types derived from enum, struct, union, and class.

   

space.gif

  • typedef enum type_declaration_identifier;
  • typedef struct type_declaration_identifier;
  • typedef union type_declaration_identifier;
  • typedef class type_declaration_identifier;
  • typedef type_declaration_identifier;
   

space.gif

   

space.gif

  ../images/main/bullet_star_pink.gif Example - typedef
   

space.gif


  1 `timescale 1ns/10ps
  2 
  3 // Type define a struct
  4 typedef struct {
  5   byte a;
  6   reg  b;
  7   shortint unsigned c;
  8 } myStruct;
  9 
 10 module typedef_data ();
 11 
 12 // Full typedef here
 13 typedef integer myinteger;
 14 
 15 // Typedef declaration without type
 16 typedef myinteger;
 17 // Typedef used here
 18 myinteger a = 10;
 19 myStruct object = '{10,0,100};
 20 
 21 initial begin
 22   $display ("a = %d", a);
 23   $display ("Displaying object");
 24   $display ("a = %b b = %b c = %h", object.a, object.b, object.c);
 25    #1  $finish;
 26 end
 27 
 28 endmodule
You could download file typedef_data.sv here
   

space.gif

  ../images/main/bullet_star_pink.gif Simulator Output
   

space.gif

 a =          10
 Displaying object
 a = 00001010 b = 0 c = 0064
   

space.gif

   

space.gif

   

space.gif

   

space.gif

space2.gif

space2.gif

space2.gif

space2.gif

space2.gif

  

Copyright © 1998-2014

Deepak Kumar Tala - All rights reserved

Do you have any Comment? mail me at:deepak@asic-world.com