我个人的看法:
int ret = 0, i, *reg;
int size = sizeof(Regs)/sizof(Reg);
for(i = 0; i<size; i++)
{
reg= (uint*)Regs[i].Number;
*reg=0;
}
return ret;
该行int ret = 0, i, *reg;
相当于
int ret;
ret = 0; //return value, if nothing changes it while running the sub, the return is (positive) as every C routine should do
int i; // i is what it is, no initialisation is performed
int* reg; //reg is what it is, no initialisation is performed.
该行int size = sizeof(Regs)/sizof(Reg);
定义size
为称为缓冲区Regs
及其类型的基本数据字段之间的原子维度Reg
。用于迭代结构本身(注意:在 C 中,Regs 不一定是缓冲区/数组/流,就 Sizeof 而言它比 regs 大是必要的。
循环从for
Reg 内 Number 字段的位置开始在每次迭代中将 n 字节归零(假设Number
是 32bits = 4 bytes long integer 从 byte 4 到 byte 7 inside Reg
)。
(uint*) 转换在 C 中是正常的,因为在处理内存时,简单的 (uint) 可能不足以跨越整个可寻址堆。我很少发现 (int*) 强制转换来迭代堆。
最后,在没有任何失败之后(在这种情况下没有任何代码可以失败,因为甚至没有使用 ret),返回值是 0 = 正返回。
为了更好地解释 for 循环中所做的事情,假设 Regs 是一个结构,其中包含一行中的 4 个 Reg 实例(某种数组),每个 Reg 是 32 字节宽,第二个字段(从 4 到 7 的字节)被称为Number
(例如 32 位整数字段)。在 for 循环运行之前和之后,内存的逐字节可视化(为便于使用和读取的 DECIMAL 格式)可以是:
before: 111910460 § 721672678 § 1941200806 § -1183627007 § 1586684153 § 1875498315 § 1260999030 § 1325944862 § 1065932391 § 1844134883 § 1605637187 § -1318663956 § 233262241 § 1220589880 § 1712611369 § -2095694326 § -1982972241 § 1536475566 § 1550414594 § 60661453 § 1920891323 § 1052971320 § 151058183 § -693448823 § -763585993 § -1546059240 § -638901203 § 1592652624 § -26126893 § 359938920 § 730403663 § -2119128428 § 22506289 § 329168535 § 1888110366 § -1324425487 § -2128177580 § -1447190387 § -2102707104 § -834692095 § 233601466 § -2368015 § -1247566469 § -496146592 § 1399945760 § -433672213 § -1874762262 § -240141582 § 1361991330 § -2100310671 § -1716316415 § 1113810979 § 837914061 § -2004720198 § -499664162 § -581537344 § -1876582939 § -855186203 § -477447744 § 609476093 § -1551962613 § 1342130125 § -1245085596 § 70042099 § 853203728 § -1216264601 § -821207587 § -663767272 § 1811963624 § -1359626002 § 587239161 § 412800157 § 1308828835 § -484000995 § 1196157114 § 1554729984 § -588907472 § -862275327 § 2141670903 § -496863553 § -1461319540 § 2011880048 § 724185989 § -523083707 § 535075127 § -1252818631 § -1535682266 § 1731550626 § -1513281783 § 2056573089 § 542455754 § -1663652432 § 209157746 § -917714063 § -62336558 § -335893804 § -455431912 § -1338920623 § 966843505 § 698158966 § -1748732016 § -710422429 § 429351988 § 1404039358 § 1828069719 § -1849911876 § -1756314151 § 1046003361 § -1124626131 § 422202 § 608265685 § 1538084062 § -1342247255 § 1734342148 § -2095965518 § 544674987 § -12582890 § 1365311130 § 1104188373 § 688131395 § -1615783097 § 755406204 § -151161805 § 1955152994 § -427907710 § 700996102 §
after: 111910460 § 721672678 § 1941200806 § -1183627007 § 0 § 0 § 0 § 0 § 1065932391 § 1844134883 § 1605637187 § -1318663956 § 233262241 § 1220589880 § 1712611369 § -2095694326 § -1982972241 § 1536475566 § 1550414594 § 60661453 § 1920891323 § 1052971320 § 151058183 § -693448823 § -763585993 § -1546059240 § -638901203 § 1592652624 § -26126893 § 359938920 § 730403663 § -2119128428 § 22506289 § 329168535 § 1888110366 § -1324425487 § 0 § 0 § 0 § 0 § 233601466 § -2368015 § -1247566469 § -496146592 § 1399945760 § -433672213 § -1874762262 § -240141582 § 1361991330 § -2100310671 § -1716316415 § 1113810979 § 837914061 § -2004720198 § -499664162 § -581537344 § -1876582939 § -855186203 § -477447744 § 609476093 § -1551962613 § 1342130125 § -1245085596 § 70042099 § 853203728 § -1216264601 § -821207587 § -663767272 § 0 § 0 § 0 § 0 § 1308828835 § -484000995 § 1196157114 § 1554729984 § -588907472 § -862275327 § 2141670903 § -496863553 § -1461319540 § 2011880048 § 724185989 § -523083707 § 535075127 § -1252818631 § -1535682266 § 1731550626 § -1513281783 § 2056573089 § 542455754 § -1663652432 § 209157746 § -917714063 § -62336558 § -335893804 § -455431912 § -1338920623 § 966843505 § 698158966 § 0 § 0 § 0 § 0 § 1828069719 § -1849911876 § -1756314151 § 1046003361 § -1124626131 § 422202 § 608265685 § 1538084062 § -1342247255 § 1734342148 § -2095965518 § 544674987 § -12582890 § 1365311130 § 1104188373 § 688131395 § -1615783097 § 755406204 § -151161805 § 1955152994 § -427907710 § 700996102 §