// Old-style error handling in C int function1() { // return integer is a boolean for success: 1=true=OK, 0=false=error return 1; } int function2() { return 1; } int function3() { return 0; } void function4(int *error) { // call-by-reference parameter is an indication for errors // 0=OK, positive=error // the actual number represents the type of error *error = 0; } void function5(int *error) { *error = 0; } void function6(int *error) { *error = 49; } int main(int argc, char *argv[]) { int error; if (function1()) // boolean return type indicates success/failure if (function2()) // note the cascading of ifs, not very convenient if (function3()) printf("all functions OK\n"); else printf("error: function3\n"); else printf("error: function2\n"); else printf("error: function1\n"); function4(&error); // call-by-reference error code indicates success/failure if (!error) { // again cascading function5(&error); if (!error) { function6(&error); if (!error) printf("all functions OK\n"); } } if (error) printf("error: %d\n",error); }