| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1064 人关注过本帖
标题:有关exit函数的问题
只看楼主 加入收藏
学c
Rank: 1
等 级:新手上路
帖 子:44
专家分:0
注 册:2007-9-17
收藏
 问题点数:0 回复次数:2 
有关exit函数的问题

在编程序时总能用到exit()函数其中exit(0)和exit(1)分别表示正常退出和非正常退出。但是我用exit编译时总提醒我warning: incompatible implicit declaration of built-in function 'exit'是怎么回事呢?是要包含一些头文件吗?

搜索更多相关主题的帖子: exit 函数 
2007-09-26 17:39
百年不亮
Rank: 3Rank: 3
等 级:新手上路
威 望:8
帖 子:789
专家分:0
注 册:2006-4-14
收藏
得分:0 

Terminate the calling process after cleanup (exit) or immediately (_exit).
void exit(
int status
);
void _exit(
int status
);
Parameter
status
Exit status.
Remarks
The exit and _exit functions terminate the calling process. exit calls, in last-in-first-out (LIFO) order, the functions registered by atexit and _onexit, then flushes all file buffers before terminating the process. _exit terminates the process without processing atexit or _onexit or flushing stream buffers. The status value is typically set to 0 to indicate a normal exit and set to some other value to indicate an error.
Although the exit and _exit calls do not return a value, the low-order byte of status is made available to the waiting calling process, if one exists, after the calling process exits. The status value is available to the operating-system batch command ERRORLEVEL and is represented by one of two constants: EXIT_SUCCESS, which represents a value of 0, or EXIT_FAILURE, which represents a value of 1. The behavior of exit, _exit, _cexit, and _c_exit is as follows.
FunctionDescription
exitPerforms complete C library termination procedures, terminates the process, and exits with the supplied status code.
_exitPerforms quick C library termination procedures, terminates the process, and exits with the supplied status code.
_cexitPerforms complete C library termination procedures and returns to the caller, but does not terminate the process.
_c_exitPerforms quick C library termination procedures and returns to the caller, but does not terminate the process.

When you call the exit or _exit functions, the destructors for any temporary or automatic objects that exist at the time of the call are not called. An automatic object is an object that is defined in a function where the object is not declared to be static. A temporary object is an object created by the compiler. To destroy an automatic object before calling exit or _exit, explicitly call the destructor for the object, as follows:
myObject.myClass::~myClass();
You should not call exit from DllMain with DLL_PROCESS_ATTACH. If you want to exit the DLLMain function, return FALSE from DLL_PROCESS_ATTACH.
Requirements
FunctionRequired headerCompatibility
exit<process.h> or <stdlib.h>ANSI, Win 98, Win Me, Win NT, Win 2000, Win XP
_exit<process.h> or <stdlib.h>Win 98, Win Me, Win NT, Win 2000, Win XP


For additional compatibility information, see Compatibility in the Introduction.
Libraries
All versions of the C run-time libraries.
Example
// crt_exit.c
/* This program returns an exit code of 1. The
* error code could be tested in a batch file.
*/

#include <stdlib.h>

int main( void )
{
exit( 1 );
}

[此贴子已经被作者于2007-9-26 17:58:58编辑过]

2007-09-26 17:55
学c
Rank: 1
等 级:新手上路
帖 子:44
专家分:0
注 册:2007-9-17
收藏
得分:0 

太感谢百年老兄了!我是没有加#include <stdlib.h>头文件,我在linux上man exit为什么查不到呢?我在linux上应该怎么查这个函数呢?你写的这个我只是看懂了一个大概,可以用中文解释一下吗????

2007-09-27 09:51
快速回复:有关exit函数的问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.066317 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved