Did you know you can have multi-dimensional dynamic arrays in SystemVerilog? It's sometimes hard work, but you can, eg: int array2d4 [][]; One way to initialise this is to just call new with an assignment pattern as its argument, eg: array2d4 = new[3]('{'{0,1,2,3},'{4,5},'{6}}); If you don't do this, then calling new is hard work: you have to call it for the outer dimension and then loop round the inner dimensions calling it separately for each element. (I'll perhaps go into more detail in a future post - watch this space.) Notice also that a multi-dimensional dynamic array doesn't have to be rectangular. In the above example, each row has a different length. (Or column. Who cares?) A customer asked me what foreach did with a dynamic array that wasn't rectangular. It turns out that it copes admirably. Good old SystemVerilog. foreach(array2d4[i,j]) $display("array2d4[%0d][%0d]= %d", i, j, array2d4[i][j]); Another custome...
Comments
Post a Comment