3 ms·
one reason I can think of from the top of my head (although I never had to deal with MISRA C at all) is that if you have to add some cleanup code before your fu
by dark-star 2y ago
one reason I can think of from the top of my head (although I never had to deal with MISRA C at all) is that if you have to add some cleanup code before your function returns, then there is exactly one place and one place only to do that.
Otherwise this leads to duplication of cleanup code similar to
allocate_something()
..
if failed(foo) {
deallocate_something()
return FAILED;
}
..
deallocate_something()
return SUCCESS;
- samatman 2y agoThis is, more than anything, an argument for a `defer` statement, of the sort you can enjoy in Zig right now. Or hopefully, eventually, in C, thanks to the tireless efforts of JeanHeyde Meneide: https://thephd.dev/just-put-raii-in-c-bro-please-bro-just-one-more-destructor-bro-cmon-im-good-for-it https://thephd.dev/just-put-raii-in-c-bro-please-bro-just-on...
- layer8 2y agoMISRA C can’t mandate new language features though.
- AlotOfReading 2y agoThe MISRA people work with the C/C++ committees on upcoming language changes, which gives them loud voices to push things they want promoted.
- eddd-ddde 2y ago> certain name manglings are not guaranteed to be 1:1 and can infact “demangle” into multiple different plausible entities. Now I'm really curious, doesn't that mean some valid C++ code would fail to link for having multiple definitions of the same symbol?? I would expect name mangling to be a bijection from function prototype to string.