Chinaunix首页 | 论坛 | 博客
  • 博客访问: 533593
  • 博文数量: 78
  • 博客积分: 1913
  • 博客等级: 上尉
  • 技术积分: 829
  • 用 户 组: 普通用户
  • 注册时间: 2008-03-14 21:29
文章分类

全部博文(78)

文章存档

2011年(27)

2010年(26)

2009年(20)

2008年(5)

我的朋友

分类:

2009-11-25 16:42:58

#include <stdio.h>
unsigned char fun(int);
int main()
{
    unsigned char a;
    a =fun(1);
    printf("2nd returned:%d\n",a);
    return 0;
}
unsigned char fun(int s)
{
    unsigned char t;
    switch(s)
    {
        case 1:printf("1st the value is:%d\n",t); return t;

        case 2:printf("???\n"); return t;
    }
    
    return 0;
}



在我的XCode 3.0 (MAC 10.5.8)中新建一个"Standard Tool" of "Command Line Utility"工程, 将如上文件内容替换掉main.c,运行程序看到的结果为:




[Session started at 2009-11-25 16:34:56 +0800.]
1st the value is:1
2nd returned:0

The Debugger has exited with status 0.


但是用gcc单独编译,打印的结果是:



1st the value is:143
2nd returned:143


t自然是一个随机值.

暂时还没有搞明白是怎么回事. 
阅读(2193) | 评论(1) | 转发(0) |
给主人留下些什么吧!~~

fantacyleo2010-01-20 01:04:17

你的fun()函数里,t只作了声明,而没有赋值,所以是一个随机值,然后又把这个随机值传回给main()里的a,并打印出来,造成你看到的也是随机值