Proper Syntax for 3D-Array

I have a 2D-array to store ADC data that synthesizes/works fine in hardware:

reg [ 31 : 0 ] adcData [ 15 : 0 ]; // 16 Channels, each with 32 bit wide data
reg [31:0] reading;
adcData [ channel ] [ 31 : 0 ] <= 32'h12345678; // Set Channel Data
reading <= adcData [ channel ] [ 31 : 0 ] ; // Get Channel Data

The problem is I’d like to now up the number of ADCs… adding another dimension to the array. According to this quora post,

it seems if you want to treat it as packed, the size comes before the variable. Unpacked it comes after. However, that doesn’t seem to be how I did it above, and yet it works… so I’m not exactly sure how to fix it such that adding an extra dimension works.

For example, I’ve tried placing the declaration next to the number of channels, but no luck:

reg [ 31 : 0 ] adcData [2:0] [ 15 : 0 ]; // 3 ADCs, each with 16 Channels and 32 bits wide
reg [ 31 : 0 ] adcData [ 15 : 0 ][2:0]; // 3 ADCs, each with 16 Channels and 32 bits wide

In reply to blipton:

When declaring packed array dimensions, the range(size) comes before(left) the variable name and the unpacked dimension range comes after(right) of the variable name. When making a reference to the array, all the selected dimensions are on the right of the variable name.

When you declare adcData as

logic [ 31 : 0 ] adcData [3] [16]; // 3 ADCs, each with 16 Channels and 32 bits wide

You need to know the ordering to select the proper index. adcData[0][2] is selecting the 32-bit packed data for the 1st ADC and the 3rd channel. And adcData[0] would be selecting an array of 16 channels of the 1st ADC.

However if you declared it as

logic [ 31 : 0 ] adcData [16] [3]; // 16 Channels, each with 3 ADCs and 32 bits wide

adcData[0][2] is now selecting the 32-bit packed data for the 1st channel and the 3rd ADC. And adcData[0] would be selecting an array of 3 ADCs of the 1st channel.

For your simple statements where you are always selecting a single packed array of 32-bits, the order that you declare the dimensions does not matter. It start to become more significant when you take slices of the array or need to stream the array reformatting the layout (i.e. an array of 192 bytes).