Reputation: 135
I got vcs compile error when adding function in declaration of struct. The IEEE doc does not mention if function in struct is allowed.
I also got vcs compile error when trying to assign a default value to a field. But it is allowed in IEEE-1800-2012 7.2.2.
typedef struct {
int a = 1; //compile error here
int b;
function void func();
b = a;
endfunction
} a_struct;
So I add the command line and error info as suggested:
vcs -sverilog a.sv
Error-[V2KIIAD] Invalid initialization at declaration
....
Struct or union member field 'a' cannot be initialized at declaration.
Error-[SE] Syntax error
Following verilog source has syntax error :
"a.sv", 4: token is 'function'
function void func();
^
And my vcs version is 2013.06-SP1-10
Upvotes: 1
Views: 2812
Reputation: 3
As we know that structures are static and classes are dynamic data types. So in SV, while we are using class,we can assign values intially or in other conditions. But for structure we can't initialise any variable inside the declaration.
Upvotes: 0
Reputation: 19122
Functions declared inside structs are not supported as of IEEE Std 1800-2012. Looking over the syntax for structure declaration, a struct_union_member is a data_type_or_void and a function is not data_type.
§ 7.2 Structures
data_type ::= // from A.2.2.1 ... | struct_union [ packed [ signing ] ] { struct_union_member { struct_union_member } } { packed_dimension } struct_union_member ::= { attribute_instance } [random_qualifier] data_type_or_void list_of_variable_decl_assignments ; data_type_or_void ::= data_type | void struct_union ::= struct | union [ tagged ]
Expanding data_type from § A.2.2.1 Net and variable types
data_type ::= integer_vector_type [ signing ] { packed_dimension } | integer_atom_type [ signing ] | non_integer_type | struct_union [ packed [ signing ] ] { struct_union_member { struct_union_member } } { packed_dimension } | enum [ enum_base_type ] { enum_name_declaration { , enum_name_declaration } } { packed_dimension } | string | chandle | virtual [ interface ] interface_identifier [ parameter_value_assignment ] [ . modport_identifier ] | [ class_scope | package_scope ] type_identifier { packed_dimension } | class_type | event | ps_covergroup_identifier | type_reference
Upvotes: 1