Packed vs unpacked array

1.7k views Asked by At

I'm trying to understand how following two code snippet differs:

example 1:

logic [4:0] [2:0] a;

example 2:

typedef logic[4:0] mytype;
logic mytype [2:0] a;

For example 1, a is a packed structure and if I'm not wrong indexing will work as follow: a[0], a[1] ... a[4] will give 3 bit value (due to [2:0]).

However for example 2, a[i] where maximum index of i is 2 and each a[i] will give 5 bit vector (due to mytype).

To be both example seems equivalent to me. 2nd one just including an extra typedef. However why indexing the array is not same for both case?

1

There are 1 answers

0
dave_59 On

The error message should have been your clue that your index ranges are reversed from what you think. You should read section 7.4.5 Multidimensional arrays of the 1800-2012 LRM that has the example

Multiple packed dimensions can also be defined in stages with typedef. typedef bit [1:5] bsix; bsix [1:10] v5; // 1 to 5 varies most rapidly