源代码:
int array[] = {1,2,3};
int *p = array;
int *q = array + 2;
int v = q - p;
汇编:
...
;从栈上取指针q的地址赋值给rax
0x100003f32 <+82>: movq -0x38(%rbp), %rax
;从栈上取指针p的地址赋值给rdx
0x100003f36 <+86>: movq -0x30(%rbp), %rdx
;rax-rdx结果赋值给rax. 这里rax等于0x8
0x100003f3a <+90>: subq %rdx, %rax
;rax算术右移2位,结果赋值给rax. 这里rax就是2
0x100003f3d <+93>: sarq $0x2, %rax
...
两个整型指针相减,结果是: 地址值差值 / sizeof(int)