4 ms·
C and gotos are common from what I've seen -- userspace and kernel C code deals with error handling and resource freeing easier that way. Open to see examples
by mrmuagi 4y ago
C and gotos are common from what I've seen -- userspace and kernel C code deals with error handling and resource freeing easier that way.
Open to see examples of (good) C code that doesn't use it though.
- Gibbon1 4y agoI used goto's fairly often to separate the happy path from the unhappy one. That's way better than confusing jumbles of if statements. if(something_bad) { err = BADTHING1; goto oops; } // more stuff return 0; oops: return err; I'll add 1. keep code that performs calculations separate from code that performs side effects. In fact isolate the latter as much as possible. 2. Avoid spooky action at a distance. Code should relentlessly work towards a clear goal.