News for hackers. Stuff that matters.
Re:GCC Rust Monthly Report #9 August 2021 by tialaramex on Tuesday August 31, 2021 @09:45AM (#28367972)
> We actually also supplied a "fork" of the MISRA C doc, crossing out ~80% of it

As an example of what you'd cross out in MISRA I would expect things like the handling of switch.

MISRA says thou shalt supply default: cases in a switch. This ensures the switch is exhaustive, but at a terrible price, there are often scenarios in which there are only four possibilities A, B, C, D and MISRA obliges you to add default: and then assert this is never reached because A, B, C, D covers all the options.

Rust's match is exhaustive. If you write matches for A, B, C and D, and that compiles, there was no other option. If a library author tells Rust "Today there's A, B, C, D but maybe I need more later" with #[non_exhaustive] your A/B/C/D match doesn't compile, what if, says the compiler, there were more later? If the library author doesn't do that, but then adds E next month anyway, it's a backwards-incompatible change and gets flagged. So in Rust you get the benefit of that particular MISRA requirement built-in, always, and none of the inflexibility because the problem they're worried about was tackled by the programming language as a correctness issue.

Re:GCC Rust Monthly Report #9 August 2021 by rightbyte on Tuesday August 31, 2021 @11:49AM (#28369515)
Defensive programming. I think it is fine. But not when it is enforced by rules. The even sillier one is that any 'if-else if' has to have an 'else'.