编辑:我错了,编译器在使用浮点数时按预期工作。
好吧,gcc 4.6.3-03
确实似乎这样做了,只要表达式是整数相关的。
示例代码:
#include <cstdio>
inline int x(double y)
{
if (y == 0)
printf("Hello bob3\n");
else
printf("Why do I bother\n");
};
const int c = 0;
int main()
{
int f;
scanf("%d",&f);
x(f * c);
}
结果组装
.file "foo.cpp"
.section .rodata.str1.1,"aMS",@progbits,1
.LC0:
.string "%d"
.LC1:
.string "Hello bob3"
.section .text.startup,"ax",@progbits
.p2align 4,,15
.globl main
.type main, @function
main:
.LFB13:
.cfi_startproc
subq $24, %rsp
.cfi_def_cfa_offset 32
movl $.LC0, %edi
xorl %eax, %eax
leaq 12(%rsp), %rsi
call scanf
movl $.LC1, %edi
call puts
xorl %eax, %eax
addq $24, %rsp
.cfi_def_cfa_offset 8
ret
.cfi_endproc
.LFE13:
.size main, .-main
.ident "GCC: (Debian 4.6.3-1) 4.6.3"
.section .note.GNU-stack,"",@progbits