goto
Jumps to a label in the same function.
Easy
Generally avoided, but the "single cleanup exit" pattern is accepted (Linux kernel style):
if (!(a = malloc(n))) goto fail;
if (!(b = malloc(n))) goto free_a;
return 0;
free_a: free(a);
fail: return -1;
Spotted a mistake or want to add detail? Suggest an improvement — Content Contributors' edits are reviewed by editors before they go live.
Discussion (0)
Sign in or join free to ask questions and discuss this topic.