I inherited the (most) part of the code, which has an error tracking mechanism, where they pass a boolean to all the methods that they call, and if errors occur at different stages of execution, the method stops and returns, sometimes the default value.
Something like (BEFORE):
#include <iostream.h>
int fun1(int par1, bool& psuccess)
{
if(par1 == 42) return 43;
psuccess = false;
return -1;
}
int funtoo(int a, bool& psuccess)
{
int t = fun1(a, psuccess);
if(!psuccess)
{
return -1;
}
return 42;
}
void funthree(int b, bool& psuccess)
{
int h = funtoo(b, psuccess);
if(!psuccess)
{
return;
}
cout << "Yuppi" << b;
}
int main()
{
bool success = true;
funthree(43, success);
if(!success)
{
cout<< "Life, universe and everything have no meaning";
}
}
Note that this is a mix of C and C ++ code, just like a project.
Now a piece of magic appears C: “someone” defined a macro somewhere:
#define SUCCES_OR_RETURN if(!psuccess) return
And the above program becomes (AFTER):
#include<iostream.h>
int fun1(int par1, bool& psuccess)
{
if(par1 == 42) return 43;
psuccess = false;
return -1;
}
int funtoo(int a, bool& psuccess)
{
int t = fun1(a, psuccess);
SUCCES_OR_RETURN -1;
return 42;
}
void funthree(int b, bool& psuccess)
{
int h = funtoo(b, psuccess);
SUCCES_OR_RETURN ;
std::cout << "Yuppi" << b;
}
int main()
{
bool success = true;
funthree(43, success);
if(!success)
{
cout<< "Life, universe and everything have no meaning";
}
}
: , , . C SUCCES_OR_RETURN .. , , return, .
, - , :
- . C ++, ,
throw ( , , ). ++. - ++ 11, "" ++, ++. , ++ 11.
- . , , .
Edit
, @BlueMoon, commend, , , success, - , , :)