万年历程序debug遇到的奇怪现象

 

程序运行结果一直不正确,用GDB进行debug,发现很奇怪的问题。

进入main函数中,变量明明是初始化为0,但是在GDB中查看是一些莫明其妙的值。

如下:

ubuntu:~/programe/linuxc$ gdb -q ./a.out
Reading symbols from /home/wupeng/programe/linuxc/a.out...done.
(gdb) l
122   
123    uint32 main(int32 argc,char* argv[])
124    {
125        uint16 year = 0;
126        uint8 month = 0;
127        uint16 day = 0;
128        uint32 days = 0;
129        int i;
130       
131        unsigned short year = 0;
(gdb) set args 1701 2 1    //传入参数
(gdb) break main              //设置断点
Breakpoint 1 at 0x80486f3: file calendar.c, line 131.
(gdb) r
Starting program: /home/wupeng/programe/linuxc/a.out 1701 2 1

Breakpoint 1, main (argc=4, argv=0xbffff394) at calendar.c:131
131        unsigned short year = 0;
(gdb) print year
$1 = 62184
(gdb)

你可能感兴趣的:(debug)