1
在d語言,等同什麼是下面的語句 假設代碼: -memset的()和memcpy()使用d片
int size = 8;
int shift = 1;
int[size] skip;
int[size] suff;
memcpy(&skip[0], &skip[0]+shift, (m-shift)*(int.sizeof));
memset(&skip[0]+(m-shift),0, shift*(int.sizeof))
我想轉換將是: -
skip[0 .. size-1] = skip[shift .. size-1 ]; //For the memcpy();
skip[0 .. size-1] = 0; //For the memset();
但是這似乎並不適用於我,因爲dmd(v2.066.1)給出了錯誤slice [8..7] exceeds array bounds [0..8]
。
[0..8]表示[0,1,2,3,4,5,6,7]。所以,你需要'size'來寫'size-1'。 – Gassa