Use exit() Very Carefully
The use of the exit() function may bypass cleanup functions. In C++ you can avoid the exit()
function by throwing and catching exceptions, in C there is an error handling capability using
setjmp()
and longjmp()
. Generally setjmp() would be used in main() and longjmp would be
used where error conditions happening. This stackoverflow.com question discusses setjmp() and longjmp(). This stackoverflow.com question discusses setjmp() and longjmp().
Use exit() Very Carefully
The use of the exit() function may bypass cleanup functions. In C++ you can avoid the exit()
function by throwing and catching exceptions, in C there is an error handling capability using
setjmp()
and longjmp()
. Generally setjmp() would be used in main() and longjmp would be
used where error conditions happening. This stackoverflow.com question discusses setjmp() and longjmp().
Use exit() Very Carefully
The use of the exit() function may bypass cleanup functions. In C++ you can avoid the exit()
function by throwing and catching exceptions, in C there is an error handling capability using
setjmp()
and longjmp()
. Generally setjmp() would be used in main() and longjmp would be
used where error conditions happening. This stackoverflow.com question discusses setjmp() and longjmp().
- 26.1k
- 13
- 47
- 113
setupCursesForSnake(). setupDisplay(). setupUserLevel(). playSnake(). cleanup().
- setupCursesForSnake().
- setupDisplay().
- setupUserLevel().
- playSnake().
- cleanup().
In the function moveSnake()
The code within the if clause
and theelse clause
shouldcould be
functions functions to simplify the moveSnake()
function.
typedef enum {BEGINNER, INTERMEDIATE, EXPERT} PlayerLevel;
PlayerLevel playerLevel = INTERMEDIATE;
switch(highlightplayerLevel){
case BEGINNER:
usDelay = BEGINNER_DELAY;
halfdelay(BEGINNER_HALF_DELAY);
break;
case INTERMEDIATE:
usDelay = INTERMEDIATE_DELAY;
halfdelay(INTERMEDIATE_HALF_DELAY);
break;
case EXPERT:
usDelay = EXPERT_DELAY;
halfdelay(EXPERT_HALF_DELAY);
break;
}
setupCursesForSnake(). setupDisplay(). setupUserLevel(). playSnake(). cleanup().
In the function moveSnake()
The code within the if clause
and theelse clause
should be
functions to simplify the moveSnake()
function.
typedef enum {BEGINNER, INTERMEDIATE, EXPERT} PlayerLevel;
PlayerLevel playerLevel = INTERMEDIATE;
switch(highlight){
case BEGINNER:
usDelay = BEGINNER_DELAY;
halfdelay(BEGINNER_HALF_DELAY);
break;
case INTERMEDIATE:
usDelay = INTERMEDIATE_DELAY;
halfdelay(INTERMEDIATE_HALF_DELAY);
break;
case EXPERT:
usDelay = EXPERT_DELAY;
halfdelay(EXPERT_HALF_DELAY);
break;
}
- setupCursesForSnake().
- setupDisplay().
- setupUserLevel().
- playSnake().
- cleanup().
In the function moveSnake()
The code within the if clause
and theelse clause
could be functions to simplify the moveSnake()
function.
typedef enum {BEGINNER, INTERMEDIATE, EXPERT} PlayerLevel;
PlayerLevel playerLevel = INTERMEDIATE;
switch(playerLevel){
case BEGINNER:
usDelay = BEGINNER_DELAY;
halfdelay(BEGINNER_HALF_DELAY);
break;
case INTERMEDIATE:
usDelay = INTERMEDIATE_DELAY;
halfdelay(INTERMEDIATE_HALF_DELAY);
break;
case EXPERT:
usDelay = EXPERT_DELAY;
halfdelay(EXPERT_HALF_DELAY);
break;
}
I will not cover anything that B. Wolf has already covered. I'm also sorry that this could not be more comprehensive, I have not reviewed all the functions.
I will not cover anything that B. Wolf has already covered. I'm also sorry that this could not be more comprehensive, I have not reviewed all the functions.
I will not cover anything that B. Wolf has already covered.