What are the best methods for writing C or C ++ functions that return an int that represents a status code?
In particular, I want to know about the client, but welcome other tips.
For example, can I write something like this:
int foo() {
return 0;
}
And then use it like this:
if (foo()) {
// what to do if false, e.g. non-zero, e.g. not OK
} else {
// what to do if true, e.g. zero, e.g. OK
}
This should work, because best practices usually determine that a status code 0means that everything is in order, and also 0means falsein a logical expression.
However, this will not be good, right:
if (!foo()) {
// what to do if true
} else {
// what to do if false
}
source
share