我有简单的程序:
#include <stdio.h>
void func(int i) {
i = 1;
printf("%d\n", i);
}
int main(int argc, char *argv[]){
func(0);
return 0;
}
现在:
gcc test.c -g -o test
gdb test
(gdb) b main
Breakpoint 1 at 0x400543: file test.c, line 9.
(gdb) run
Starting program: /tmp/test
Breakpoint 1, main (argc=1, argv=0x7fffffffe458) at test.c:9
9 func(0);
(gdb) s
func (i=0) at test.c:4
4 i =1;
(gdb) p i
$1 = 0
(gdb) n
5 printf("%d\n", i);
(gdb) p i
$2 = 0
(gdb)
程序运行良好,显示“1”,但为什么 gdb 显示“0”值?
Debian 喘不过气来。
我在 gcc-4.7、gcc-4.6 上观察到了这一点。在 gcc-4.4 上一切正常。