Ask your own question, for FREE!
Computer Science 17 Online
OpenStudy (anonymous):

The main subroutine in the C sudoku game project returns different error codes according to what type of error happened during execution. For example: int main(int argc, char** argv) { // Process argc and argv, configuring the game accordingly. if (! processArgs(argc, argv)) { fprintf(stderr, "Usage: game -debug | -normal | -hard"); return 1; } // Load graphics if (! loadGraphics()) { fprintf(stderr, LINE_FILE"\nERROR: Failed to load pdcurses."); return 2; } // Generate the board if (! loadboard()) { fprintf(stderr, LINE_FILE"\nERROR: Could not generate " } }

OpenStudy (anonymous):

return 3; /* More stuff... */ // End. printf("Have a nice day!"); return 0; }

OpenStudy (anonymous):

The question is, is it okay to do this (returning numbers different from 0 if something wrong happens during execution to 'crash' the game while leaving me with a relatively meaningful error message) or do the different return values in main have some semantic value to the OS besides "something went wrong in the program" ?

OpenStudy (anonymous):

oh and LINE_FILE is just a macro to print the line number where the error occured.

OpenStudy (shadowfiend):

Generally speaking, return values other than 0 (which is typically interpreted to mean “success”) are program-specific. There's some additional work from the operating system to set a high bit of an 8-bit return code in cases of abnormal termination. More at http://stackoverflow.com/questions/1101957/are-there-any-standard-exit-status-codes-in-linux .

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!