Packed arrays can only be
made of the single bit types: (bit, logic, reg, wire, and the other net types) and recursively other
packed arrays and packed structures. Unpacked arrays can be
made up of any type.
Integer types with predefined
widths cannot have packed array dimensions declared. These types are: byte, shortint, int, longint, and integer. An integer type with a predefined width can be
treated as a single dimension packed array. The packed dimensions of these
integer types shall be numbered down to 0, such that the right-most index is 0.
byte
c2; // same as bit [7:0]
c2;
integer
i1; // same as logic signed [31:0]
i1;
Unpacked arrays can be made
of any singular type. SystemVerilog enhances fixed-size unpacked
arrays in that in addition to all other SystemVerilog variable
types, unpacked arrays may also be made of object handles (see Section 11.4)
and events (see Section 13.5).
SystemVerilog accepts a
single number instead of a range, as an alternative to a range, to specify the size of an unpacked
arrays, like C. That
is, [size] becomes the same as [size-1:0]. For example:
Editor’s Note: Is new[]
an operator, method or function (it is called a both function and an operator
in the next subsection).
4.13 Associative Array
Literals
concatenation ::=
…
|
{ array_member_label : expression { , array_member_label : expression } }
array_member_label ::=
default
| type_identifier
| constant_expression
Syntax 4-1—Associative array literal syntax
(excerpt from Annex A.8.1)
For example:
// an associative
array of strings indexed by 2-state integers, default is “foo”.
string words [int] = {default: ''foo''};
// an associative array of 4-state
integers indexed by strings, default is –1.
integer table [string]
= {"Peter":20, "Paul":22, "Mary":23, default:-1
};
If a default value is specified, then
reading a non-existent element will yield the specified default value.
Otherwise, the default initial value as described in Table 4-1 is returned.