RETURN SUCCESS VS RETURN 0

As in the title, what is the difference between RETURN SUCCESS and RETURN 0?
Thanks.
Bosco
The difference is that we all know what is 0 and nobody except of the author of this statement knows what is SUCCESS. Also nobody knows what is RETURN.:)

I can only guess that maybe SUCCESS is a manifest constant that names the same 0. Something as

#define SUCCESS 0

There are standard constants as EXIT_SUCCESS and EXIT_FAILURE in the C/C++ standard. EXIT_SUCCESS denotes 0.

So it would be better to write

return EXIT_SUCCESS;

It is the same as

return 0;
Last edited on
There is no big difference from your EntryPoint. There is some differences when using custom functions, but you will learn about it further, as you don't seem to understand them (only a tought).
The idea is that EXIT_SUCCESS can be used to return different values depending on the operating system; just in case a platform uses 0 to signal failure, and 1 to signal success for example.
According to the C/C++ standard

"If the value of status is zero or EXIT_SUCCESS, an implementation-defined form of the status successful termination is returned."


So EXIT_SUCCESS can be considered as an equivalence of 0 and indeed it is defined as 0 in most implementations. I do not know even an implementation where EXIT_SUCCESS would have a value distinguished from 0.
So EXIT_SUCCESS can be considered as an equivalence of 0 and indeed it is defined as 0 in most implementations.


That's true. But I guess it would seam more logical to use EXIT_SUCCESS in the case that an implementation does define 0 as failure, because at least what is written in your code would match what is happening; that is your code won't say return 0, and really be return 1.

But your right, I don't even know if an implementation exists which doesn't define 0 as success.

I have read that EXIT_FAILURE is more important to use in some cases, and if your using EXIT_FAILURE, you might as well use EXIT_SUCCESS.
Last edited on
@iseeplusplus
But I guess it would seam more logical to use EXIT_SUCCESS in the case that an implementation does define 0 as failure,


You are wrong. Read again the statement from the Standard I cited. 0 may not define a failure.
You are wrong. Read again the statement from the Standard I cited. 0 may not define a failure.


I don't understand what you mean? Are you saying that in the case zero defines a failure, that zero may not define a failure? That doesn't make any sense?
Last edited on
Are these words yours?

in the case that an implementation does define 0 as failure,


I said that 0 may not be defined as failure.
Last edited on
I said that 0 may not be defined as failure.


What you cited does not say that. It says that your return 0; will be translated into the implementation definition of success. Which means it may be translated into a 1.

Upon EXIT_FAILURE, your return will be translated into the implementation definition of failure. There isn't a law that I am aware of that says you can't write an operating system which defines 0 as failure.

But that was just a hypothetical to demonstrate the point I was trying to make.
Last edited on
Do you understand what you are writing?!!!

Are these words yours?!!!

But I guess it would seam more logical to use EXIT_SUCCESS in the case that an implementation does define 0 as failure


Or you had written that and did not understand what it means?

Read one more the statement from the standard

"If the value of status is zero or EXIT_SUCCESS, an implementation-defined form of the status successful termination is returned."


Or you do not understand what is written in the Standard?!!!
Last edited on
That's true. But I guess it would seam more logical to use EXIT_SUCCESS in the case that an implementation does define 0 as failure, because at least what is written in your code would match what is happening; that is your code won't say return 0, and really be return 1.


Yes, except that a return of zero is also standard. Regardless, using EXIT_SUCCESS removes the dependence on a "magic number." In other words, if the standard were to change the return value for success (not going to happen but as an example) you wouldn't have to change all of your return zeros, EXIT_SUCCESS could just be changed in the implementation.

It's important to note this distinction when developing maintainable software. In this particular case, the standard makes either roughly the same. When developing an API or using 3rd party libraries, always try to break dependencies on implementation-specific values.
Or you had written that and did not understand what it means?

Read one more the statement from the standard


Your misunderstanding. The implementation is the operating system. The C++ standard your talking about relates to a programming language.
Last edited on
@iseeplusplus
Your misunderstanding. The implementation is the operating system. The C++ standard your talking about relates to a programming language.


It is you who can not understand that whether 0 or EXIT_SUCCESS will be specified an implementation-defined form of the status successful termination is returned."
It is you who doesn't seam to understand, that when a program returns EXIT_FAILURE, it may be translated into an implementation specific definition of failure. Show me where it is stated that an implementation cannot define 0 as failure?
Last edited on
Using EXIT_SUCCES you also do not know what will be implementation specific definition of success. But you write programs according to the C/C++ standard. And others programmers who read your code also do not know what is the implementation specific definition of success. It is only important whether success is returned to an operation system. So if you will write return EXIT_SUCCESS it wil say nothing more for the reader of the program than if you will write return 0.
Last edited on
1
2
3
4
5
6
if ( success ) {
    return EXIT_SUCCESS;
}
else {
    return EXIT_FAILURE;
}


looks slightly better in my opinion than:

1
2
3
4
5
6
if ( success ) {
    return 0;
}
else {
    return EXIT_FAILURE;
}


But its really not that important.
Last edited on
Or than return not success; xP

return ERROR_SUCCESS; ... ┬┐what?
Topic archived. No new replies allowed.