|
发表于 2019-6-30 16:22:25
|
显示全部楼层
- y = ((x = 3 * y, x + 1), x - 1);
复制代码
第一步执行 x = 3 * y
第二步执行 y = x - 1
x + 1没有执行,编译器直接优化掉了
- y = ((x = 3 * y, x + 1), x - 1);
复制代码
相当于
- x = 3 * y;
- x + 1;
- y = x - 1;
复制代码
- #include <stdio.h>
- int main(void)
- {
- int x = 1234, y = 5678;
- y = ((x = 3 * y, x + 1), x - 1);
- printf("%d\n", y);
- return 0;
- }
复制代码
- .file "main.c"
- .text
- .def __main; .scl 2; .type 32; .endef
- .section .rdata,"dr"
- .LC0:
- .ascii "%d\12\0"
- .text
- .globl main
- .def main; .scl 2; .type 32; .endef
- .seh_proc main
- main:
- pushq %rbp
- .seh_pushreg %rbp
- movq %rsp, %rbp
- .seh_setframe %rbp, 0
- subq $48, %rsp
- .seh_stackalloc 48
- .seh_endprologue
- call __main
- movl $1234, -4(%rbp)
- movl $5678, -8(%rbp)
- movl -8(%rbp), %edx
- movl %edx, %eax
- addl %eax, %eax
- addl %edx, %eax
- movl %eax, -4(%rbp)
- movl -4(%rbp), %eax
- subl $1, %eax
- movl %eax, -8(%rbp)
- movl -8(%rbp), %eax
- movl %eax, %edx
- leaq .LC0(%rip), %rcx
- call printf
- movl $0, %eax
- addq $48, %rsp
- popq %rbp
- ret
- .seh_endproc
- .ident "GCC: (GNU) 7.4.0"
- .def printf; .scl 2; .type 32; .endef
复制代码 |
|