Skip to content

Instantly share code, notes, and snippets.

@Shinpeim
Created April 10, 2015 07:17
Show Gist options
  • Save Shinpeim/a6fe552af051800fd26d to your computer and use it in GitHub Desktop.
Save Shinpeim/a6fe552af051800fd26d to your computer and use it in GitHub Desktop.
// たとえばこんなかんじ
int nyan(){
int *p1 = (int *)malloc(sizeof(int))
int *p2 = (int *)malloc(sizeof(int))
int *p3 = (int *)malloc(sizeof(int))
int retval = 0;
// ごちゃごちゃなんかやる
//!エラーが起こった!
if (err) {
retval = -1; // エラーコードを入れて
goto cleanup; //cleanupにすっ飛ぶ
}
//正常系は続く
retval = 1; //正常系の場合の返り値を入れて
cleanup:
free(p1);
free(p2);
free(p3);
return retval;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment