小编Dan*_*amp的帖子

如何让MSVC将未初始化的数据放入.bss?

我正在使用自定义构建系统(在Visual Studio外部)构建DLL,并且我无法获得未初始化的数据以显示在该.bss部分中; 编译器把它归结为.data.这膨胀了最终的二进制大小,因为它充满了巨大的零数组.

例如(示例中的小1KB数组,但实际缓冲区要大得多):

int uninitialized[1024];
int initialized[1024] = { 123 };
Run Code Online (Sandbox Code Playgroud)

编译器发出如下所示的程序集:

PUBLIC  _initialized
_DATA   SEGMENT
COMM    _uninitialized:DWORD:0400H
_initialized DD 07bH
    ORG $+4092
_DATA   ENDS
Run Code Online (Sandbox Code Playgroud)

最终在目标文件中如下所示:

SECTION HEADER #3
   .data name
       0 physical address
       0 virtual address
    1000 size of raw data
     147 file pointer to raw data (00000147 to 00001146)
       0 file pointer to relocation table
       0 file pointer to line numbers
       0 number of relocations
       0 number of line numbers
C0400040 flags
         Initialized …
Run Code Online (Sandbox Code Playgroud)

c c++ visual-c++

7
推荐指数
1
解决办法
954
查看次数

标签 统计

c ×1

c++ ×1

visual-c++ ×1