简体   繁体   English

什么是“ EXIT_FAILURE”类?

[英]What class is “EXIT_FAILURE”?

In the main function, I had a lot of error testing code to make sure I successfully located and opened some files. 在主要功能中,我有很多错误测试代码,以确保成功找到并打开了一些文件。 So since I did that a lot, I made it a separate, void, function. 因此,由于我做了很多事情,因此将其设为独立的无效函数。 When I previously had "return EXIT_FAILURE" in the main function it would work just like I wanted it to. 当我以前在主函数中使用“ return EXIT_FAILURE”时,它将按我希望的那样工作。 But when I put it in a secondary function I named errorTest, it gets on me about returning something after declaring it a void function. 但是,当我将它放在一个名为errorTest的辅助函数中时,它在声明它为void函数后返回一些东西。 So, what class is "EXIT_FAILURE", so I can differently declare that void function into returning whatever class "EXIT_FAILURE" is? 那么,什么类是“ EXIT_FAILURE”,那么我可以不同地声明void函数返回什么类“ EXIT_FAILURE”?

(and yes, I included the library cstdlib) (是的,我包含了库cstdlib)

It's a preprocessor macro defined by #include <cstdlib> . 这是#include <cstdlib>定义的预处理程序宏。

It expands to an integral constant expression. 它扩展为整数常量表达式。 This is not necessarily of type int , however it must have a value within the valid range of int so that it can be passed to exit() . 该值不一定是int类型,但是它必须具有int有效范围内的值,以便可以将其传递给exit()

it's an integer. 这是一个整数。 Declare your function as int. 将函数声明为int。

EXIT_FAILURE是在stdlib.h (或cstdlib )中声明的int ,因此它是原始类型,而不是类。

EXIT_SUCCESSEXIT_FAILURE是在stdlib.hcstdlib定义的宏。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM