|
|
|

|
|
|
|
|
|

|
|
 |
Structure Literals
|
|
|
Structure literals are syntactically similar to C initializers. Structure literals must have a type, either from context or a cast. When an array of structures is initialized, the nested braces should reflect the array and the structure. |
|
|

|
|
|
|
|
|

|
|
 |
Example - Struct Literals
|
|
|

|
|
|
1 `timescale 1ns/100ps
2 // Type define a struct
3 typedef struct {
4 byte a;
5 reg b;
6 shortint unsigned c;
7 } myStruct;
8
9 module struct_literals ();
10
11 myStruct object = '{10,0,100};
12
13 myStruct objectArray [0:1] = '{'{10,0,100},'{11,1,101}};
14
15 initial begin
16 $display ("a = %b b = %b c = %h", object.a, object.b, object.c);
17 object.a = 15;
18 $display ("a = %b b = %b c = %h", object.a, object.b, object.c);
19 object.c = 16'hDEAD;
20 $display ("a = %b b = %b c = %h", object.a, object.b, object.c);
21 $display ("Printing array of objects");
22 $display ("a = %b b = %b c = %h",
23 objectArray[0].a, objectArray[0].b, objectArray[0].c);
24 $display ("a = %b b = %b c = %h",
25 objectArray[1].a, objectArray[1].b, objectArray[1].c);
26 #1 $finish;
27 end
28
29 endmodule
You could download file struct_literals.sv here
|
|
|

|
|
 |
Simulator Output
|
|
|

|
|
|
a = 00001010 b = 0 c = 0064
a = 00001111 b = 0 c = 0064
a = 00001111 b = 0 c = dead
Printing array of objects
a = 00001010 b = 0 c = 0064
a = 00001011 b = 1 c = 0065
|
|
|

|
|
|

|
|
|

|
|
|
|
|
|

|
|
|
|
|
|

|
|
Copyright © 1998-2025 |
Deepak Kumar Tala - All rights reserved |
Do you have any Comment? mail me at:deepak@asic-world.com
|
|