- 论坛徽章:
- 1
|
原帖由 legend1860 于 2008-11-9 14:08 发表 ![]()
(&a+1)中的&a取出来的也是数组的地址,不是数组的首地址,int *p = (int *) (&a+1);其中P指向数组的最后一个地址的下一个地址
*(p-1)就是数组最后一个元素!
正解.
(&a+1)直接就偏移了5个int*的距离,然后强制转换成int*,p-1便指向了数组的末尾.
.file "tmp.c"
.def ___main; .scl 2; .type 32; .endef
.section .rdata,"dr"
LC0:
.ascii "%d %d\0"
.text
.globl _main
.def _main; .scl 2; .type 32; .endef
_main:
leal 4(%esp), %ecx
andl $-16, %esp
pushl -4(%ecx)
pushl %ebp
movl %esp, %ebp
pushl %ecx
subl $52, %esp
call ___main
movl $1, -28(%ebp)
movl $2, -24(%ebp)
movl $3, -20(%ebp)
movl $4, -16(%ebp)
movl $5, -12(%ebp)
leal -28(%ebp), %eax
addl $20, %eax
movl %eax, -8(%ebp)
movl -8(%ebp), %eax
subl $4, %eax
movl (%eax), %edx
leal -28(%ebp), %eax
addl $4, %eax
movl (%eax), %eax
movl %edx, 8(%esp)
movl %eax, 4(%esp)
movl $LC0, (%esp)
call _printf
movl $0, %eax
addl $52, %esp
popl %ecx
popl %ebp
leal -4(%ecx), %esp
ret
.def _printf; .scl 2; .type 32; .endef
|
|
|