C语言中函数的返回数据类型
我必须在函数中使用 exit(1) 命令。 它与使用它的函数的返回数据类型有什么关系吗?
i have to use exit(1) command in a function.
Does it have anything to do with the return data type of the function in which it is being used?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不会。
exit
函数永远不会返回,而是终止调用它的进程。 C 编译器对它没有直观的理解,并将其视为任何其他void
返回函数。这确实意味着虽然
exit
将结束你的函数,但 C 编译器不会这样看待它。因此它仍然需要一个有效的返回,否则它会发出警告/错误(启用足够高的错误级别)。但这很容易解决No. The
exit
function never returns but instead terminates the process it's called from. The C compiler has no intuitive understanding of it and treats it like any othervoid
returning function.This does mean though that while
exit
will end your function the C compiler doesn't see it that way. Hence it will still want a valid return else it will spit out warnings /errors (with a high enough error level enabled). But this is easy enough to work around