小编Gil*_*Dev的帖子

为什么clang不像#define那样优化全局const?

我有这个测试程序,使用#define常量:

#include <stdio.h>

#define FOO 1

int main()
{
    printf("%d\n", FOO);

    return 0;
}
Run Code Online (Sandbox Code Playgroud)

使用"Apple LLVM版本10.0.0(clang-1000.11.45.5)"编译时,我得到8432字节的可执行文件.这是装配清单:

    .section    __TEXT,__text,regular,pure_instructions
    .build_version macos, 10, 14
    .globl  _main                   ## -- Begin function main
    .p2align    4, 0x90
_main:                                  ## @main
    .cfi_startproc
## %bb.0:
    pushq   %rbp
    .cfi_def_cfa_offset 16
    .cfi_offset %rbp, -16
    movq    %rsp, %rbp
    .cfi_def_cfa_register %rbp
    subq    $16, %rsp
    leaq    L_.str(%rip), %rdi
    movl    $1, %esi
    movl    $0, -4(%rbp)
    movb    $0, %al
    callq   _printf
    xorl    %esi, %esi
    movl    %eax, -8(%rbp)          ## 4-byte Spill
    movl    %esi, …
Run Code Online (Sandbox Code Playgroud)

c c++ optimization constants clang

4
推荐指数
1
解决办法
337
查看次数

标签 统计

c ×1

c++ ×1

clang ×1

constants ×1

optimization ×1