bitcoin-sv / sol2scrypt

Solidity to sCrypt Transplier
BSD 3-Clause "New" or "Revised" License
1 stars 0 forks source link

Multidimensional Arrays #151

Closed zhfnjust closed 2 years ago

zhfnjust commented 2 years ago

scrypt

int[2][3] ccc = [[1, 2, 1], [3, 4, 3]];

solidity

uint8[2][3] memory ccc =[[1,2],[3,4],[5,6]];
xhliu commented 2 years ago

sCrypt is the same w/ C/C++/Java

int x[3][2] = {{0,1}, {2,3}, {4,5}};

xhliu commented 2 years ago

Solidity is different from C https://ethereum.stackexchange.com/questions/64331/why-is-multidimensional-array-declaration-order-reversed https://ethereum.stackexchange.com/questions/11870/create-a-two-dimensional-array-in-solidity#comment85329_11888

https://docs.soliditylang.org/en/v0.8.11/types.html#arrays

For example, an array of 5 dynamic arrays of uint is written as uint[][5]. The notation is reversed compared to some other languages. In Solidity, X[3] is always an array containing three elements of type X, even if X is itself an array. This is not the case in other languages such as C.

https://docs.soliditylang.org/en/v0.8.11/types.html#array-literals uint24[2][4] memory x = [[uint24(0x1), 1], [0xffffff, 2], [uint24(0xff), 3], [uint24(0xffff), 4]];

freedomhero commented 2 years ago

resolved in https://github.com/sCrypt-Inc/sol2scrypt/pull/176