这个代码有什么问题?

value = func(value++)

有什么问题?

我知道我就不来问了。。。

#include <stdio.h>
#include <stdlib.h>

int func(int a)
{
   int b;
   b = a + 20;
   return b;
}

int main(int argc, char* argv[]) {
   int val = 10;
   val = func(val++);
   printf("val = %d\n", val);
}

上面这种用法?arm64架构的反汇编如下:

对应文本内容如下(已显示字节码):

__text:0000000100007F0C             _main
__text:0000000100007F0C
__text:0000000100007F0C             var_20          = -0x20
__text:0000000100007F0C             var_18          = -0x18
__text:0000000100007F0C             var_14          = -0x14
__text:0000000100007F0C             var_10          = -0x10
__text:0000000100007F0C             var_4           = -4
__text:0000000100007F0C             var_s0          =  0
__text:0000000100007F0C
__text:0000000100007F0C FF C3 00 D1                 SUB             SP, SP, #0x30
__text:0000000100007F10 FD 7B 02 A9                 STP             X29, X30, [SP,#0x20+var_s0]
__text:0000000100007F14 FD 83 00 91                 ADD             X29, SP, #0x20
__text:0000000100007F18 48 01 80 52                 MOV             W8, #0xA
__text:0000000100007F1C A0 C3 1F B8                 STUR            W0, [X29,#var_4]
__text:0000000100007F20 E1 0B 00 F9                 STR             X1, [SP,#0x20+var_10]
__text:0000000100007F24 E8 0F 00 B9                 STR             W8, [SP,#0x20+var_14]
__text:0000000100007F28 E8 0F 40 B9                 LDR             W8, [SP,#0x20+var_14]
__text:0000000100007F2C 00 05 00 11                 ADD             W0, W8, #1
__text:0000000100007F30 E0 0F 00 B9                 STR             W0, [SP,#0x20+var_14]
__text:0000000100007F34 E0 03 08 AA                 MOV             X0, X8
__text:0000000100007F38 ED FF FF 97                 BL              _func
__text:0000000100007F3C E0 0F 00 B9                 STR             W0, [SP,#0x20+var_14]
__text:0000000100007F40 E8 0F 40 B9                 LDR             W8, [SP,#0x20+var_14]
__text:0000000100007F44 E1 03 08 AA                 MOV             X1, X8
__text:0000000100007F48 FE 03 00 91                 MOV             X30, SP
__text:0000000100007F4C C1 03 00 F9                 STR             X1, [X30,#0x20+var_20]
__text:0000000100007F50 00 00 00 90                 ADRP            X0, #aValD@PAGE ; "val = %d\n"
__text:0000000100007F54 00 90 3E 91                 ADD             X0, X0, #aValD@PAGEOFF ; "val = %d\n"
__text:0000000100007F58 07 00 00 94                 BL              _printf
__text:0000000100007F5C 08 00 80 52                 MOV             W8, #0
__text:0000000100007F60 E0 0B 00 B9                 STR             W0, [SP,#0x20+var_18]
__text:0000000100007F64 E0 03 08 AA                 MOV             X0, X8
__text:0000000100007F68 FD 7B 42 A9                 LDP             X29, X30, [SP,#0x20+var_s0]
__text:0000000100007F6C FF C3 00 91                 ADD             SP, SP, #0x30
__text:0000000100007F70 C0 03 5F D6                 RET
__text:0000000100007F70             ; End of function _main

你觉得有什么问题?

https://twitter.com/ibsparkes/status/1304120472855105536?s=21

我是没有看出来有什么问题

上面也贴汇编了,简化下来就是

push ebx
inc ebx
call func
mov ebx, eax

那么这个可能会出现什么问题呢

shouldn’t gcc warn against this?

iBSpark这句话我没看懂他想表达什么