SystemVerilog“struct”表示相同或不同数据类型的集合。
struct可以作为一个整体使用,也可以单独通过名称引用组成这个struct的元素。由于这些元素的数据类型可能不相同,所以不能够使用数组。
如果需要在多个module或者类中使用相同的struct,则应该将struct定义(`typedef)放到SystemVerilog package中,然后将其导入到每个module或者class。
默认情况下,struct都是unpacked的,我们也可以显式地加上关键字。下面是一个简单的示例,展示了array和struct的区别。
// Normal arrays -> a collection of variables of same data type int array [10]; // all elements are of type ‘int’ bit [7:0] mem [256]; // all elements are of type ‘bit’ // Structures -> a collection of variables of same or different data types struct { byte val1; int val2; string val3; } DataValue;
当然,我们也可以定义一个数组,其中数组中的每一个数据项都是一个struct.
DataValue v1[20]; //array of structures
struct
{
byte val1;
int val2[10]; //array within a structure
string val3; } DataValue;
审核编辑:汤梓红
-
Verilog
+关注
关注
30文章
1370浏览量
114167 -
System
+关注
关注
0文章
166浏览量
38466 -
Struct
+关注
关注
0文章
31浏览量
11220
原文标题:SystemVerilog中的struct
文章出处:【微信号:芯片验证工程师,微信公众号:芯片验证工程师】欢迎添加关注!文章转载请注明出处。
发布评论请先 登录
SystemVerilog中的“const”类属性
SystemVerilog的断言手册
typedef struct的用法
SystemVerilog中$cast的应用
Systemverilog中的union
SystemVerilog中的Semaphores
C++中struct和class的区别?
Systemverilog中的Driving Strength讲解

SystemVerilog中的struct
评论