4 ms·
> "Do not use goto, setjmp or longjmp." Error handling in C without those primitives will almost always result in horrible code. They should've made an excepti
by uasm 8y ago
> "Do not use goto, setjmp or longjmp."
Error handling in C without those primitives will almost always result in horrible code. They should've made an exception here: "goto error;" should've been allowed and encouraged.
- coldtea 8y ago>Error handling in C without those primitives will almost always result in horrible code They don't care for nice code. They care for easily statically checked and verified code.
- philpem 8y agoAs I said else-thread, there's actually a variation in MISRA-C-2012 (or possibly one of the addenda) for this. Error handling using 'goto' is allowed, as long as you're jumping forward (i.e. to or near the end of the function). You can't go backwards through the code. It may require a variation in the project's coding spec but it's certainly possible (because I've been there and done it!)
- nwmcsween 8y agogoto is fine but anything that uses setjmp or longjmp for error handling is absolute garbage code