If an index
expression is of a 4-state type, and the array is of a 4-state type, an X or Z in the
index expression shall cause a read to return X, and a
write to issue a run-time warning. If an index expression is of a 4-state type,
but the array is of a 2-state type, an X or Z in the index expression shall generate
a run-time warning and be treated as 0. If an index expression is out of bounds, a
run-time warning can be generated.
The result of
reading from an array of 2-state variables, such as int, with an out of range index is
indeterminate. Writing to an array with an out of range index performs no
operation. Implementations can generate a warning if an out of range index
occurs for a read or write operation.
If an index
expression is out of the address bounds or if any bit in the address is X or Z, then the index shall be invalid. The result of reading from an
array with an invalid index shall return the default uninitialized
value for the array element type. Writing to an array with an invalid index
shall perform no operation. Implementations can generate a warning if an
invalid index occurs for a read or write operation of an array.
Arrays can be passed as arguments to tasks or functions. The rules
that govern array argument passing by value are the same as for array
assignment (see Section 10.4) are the same
as for array assignment. When an array argument is passed by value, a copy of the array
is passed to the called task or function. This is true for all array types:
fixed-size, dynamic, or associative.
Passing
fixed-size arrays as arguments to subroutines requires that the actual argument
and the formal argument in the function declaration be of compatible types and
that all sized dimensions be of the same size. Note that unsized
dimensions can occur in dynamic arrays and in formal arguments of import DPI
functions. If one of dimensions of a formal is unsized, then any size of the
corresponding dimension of an actual is accepted.
reg
b[3:1][3:1]; //error: incompatible type OK:
assignment compatible type
event b[3:1][3:1]; //error: incompatible type
Queues
are declared using the same syntax as unpacked arrays, but specifying $ as the array size.
The maximum size of a queue can be
limited by specifying its optional right bound (last index).
variable_dimension ::= // from Annex A.2.5
{ sized_or_unsized_dimension }
| associative_dimension
| queue_dimension
queue_dimension ::= [ $ [ : constant_expression ] ]
Syntax 4-8 — Declaration of queue dimension
constant_expression must evaluate to a positive integer value.
For example:
byte
q1[$]; // A queue of bytes
string names[$] = {
"Bob" }; // A queue of strings with one element
integer Q[$] = { 3,
2, 7 }; // An initialized queue of integers
bit q2[$:255]; // A
queue whose maximum size is 256 bits
The empty array literal {} is
used to denote an empty queue. If an initial value is not provided in the
declaration, the queue variable is initialized to the empty queue.
—
An invalid index (i.e., a 4-state expression with X's or Z's, or a value that lies outside 0...$+1) shall cause a
write operation to be ignored and a run-time warning to be issued. Note that
writing to Q[$+1] is legal.
¾
A queue declared with a right bound
[$:N] shall be limited to the indexes 0 through
N (its maximum size will be N+1). An index that lies outside
these limits shall be invalid, therefore, a write operation past the end of the
queue shall be ignored and issue a warning. The warning can be issued at either
compile time or run time, as soon as it is possible to determine that the index
lies outside the queue limit.