且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

来自数组 0 初始化的奇怪程序集

更新时间:2022-05-01 00:27:18

第 2 行和第 5 行的原因是因为您在数组初始值设定项中指定了 0.编译器将初始化所有常量,然后使用 memset 填充其余的常量.如果你在初始化器中放两个零,你会看到它是 strw(字而不是字节)然后 memset 8 个字节.

The reason for lines 2 and 5 is because you specified a 0 in the array initializer. The compiler will initialize all constants then pad out the rest using memset. If you were to put two zeros in your initializer, you'd see it strw (word instead of byte) then memset 8 bytes.

至于padding,它只是用来对齐内存访问——一般情况下不应该使用数据,所以memsetting很浪费.

As for the padding, it's only used to align memory accesses -- the data shouldn't be used under normal circumstances, so memsetting it is wasteful.

为了记录,我对上面的 strw 假设可能是错误的.我 99% 的 ARM 经验是在 iPhone 上反转 GCC/LLVM 生成的代码,所以我的假设可能不会延续到 MSVC.

For the record, I may be wrong about the strw assumption above. 99% of my ARM experience is reversing code generated by GCC/LLVM on the iPhone, so my assumption may not carry over to MSVC.