免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
楼主: xumouxin1
打印 上一主题 下一主题

exit()和return 有什么区别? [复制链接]

论坛徽章:
0
31 [报告]
发表于 2006-12-05 22:37 |只看该作者
原帖由 nully 于 2006-12-5 22:18 发表
喜欢橙兄的头像


红颜祸水
色字头上一把刀
情花之毒, 非得断肠之草来解
--阿弥陀佛

论坛徽章:
0
32 [报告]
发表于 2006-12-06 10:04 |只看该作者
/*读文件*/
        if((iSize = read(fd,buf,1024)) == -1)
        {
                printf("Read Error\nError No=%\n",errno); ----->这行有错误!!!!!!!
                exit(1);
        }

论坛徽章:
0
33 [报告]
发表于 2006-12-06 10:14 |只看该作者
APUE中有下面的描述:
When a C program is executed by the kernelby one of the exec functions, which we describe in Section 8.10a special start-up routine is called before the main function is called.
......
If the start-up routine were coded in C (it is often coded in assembler) the call to main could look like

    exit(main(argc, argv));

另外:在IO操作上务必小心。

论坛徽章:
0
34 [报告]
发表于 2006-12-06 10:42 |只看该作者
原帖由 飞灰橙 于 2006-12-5 22:37 发表


红颜祸水
色字头上一把刀
情花之毒, 非得断肠之草来解
--阿弥陀佛

空即是色,色即是空
--阿弥陀佛

论坛徽章:
0
35 [报告]
发表于 2006-12-06 11:37 |只看该作者
原帖由 isjfk 于 2006-12-6 10:42 发表

空即是色,色即是空
--阿弥陀佛

今天我想空一下

论坛徽章:
0
36 [报告]
发表于 2006-12-06 11:54 |只看该作者

回复 33楼 wqch 的帖子

for C programs, there is a start-up stub before executing main() function, which will setup the stack.

if main() returns with return(n), the stub will clean up stack. in this case, as the stack has overrun, then SEGV signal will raise. if main() is terminated by exit(n), no action to clean up stack.

论坛徽章:
0
37 [报告]
发表于 2006-12-06 12:10 |只看该作者
我觉得如果在 main() 里面堆栈溢出,那根本就没有回到 stub 的机会。因为 main 压在堆栈里面,用来返回 stub 的 IP 指针已经被破坏了

论坛徽章:
0
38 [报告]
发表于 2006-12-06 13:18 |只看该作者
char buf[1024];
   ....................................
..................................

        /*读文件*/
        if((iSize = read(fd,buf,1024)) == -1)
.....................................
这样可以吗?会存在越界问题吗?


我想应该不会吧,当读到文件尾会返回,我也不能肯定。
最好是能先求出文件的大小。

论坛徽章:
0
39 [报告]
发表于 2006-12-06 13:27 |只看该作者
理不出头绪, 只能看看 原码才能解决, 但有看不懂

论坛徽章:
0
40 [报告]
发表于 2006-12-06 13:31 |只看该作者

程序错在这里

int main()
{
        int fd;
        char buf[1024];
        int iSize;

        memset(buf,0x00,1204);
。。。。
注意:
程序里是1204,定义的数组长度为1024!
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP