|
|
Subscribe / Log in / New account

Fixing programmers

Fixing programmers

Posted Mar 15, 2019 13:19 UTC (Fri) by anselm (subscriber, #2796)
In reply to: Fixing programmers by jschrod
Parent article: Cook: security things in Linux v5.0

The Unix guys worked shoulder-to-shoulder with the C guys

Not just that. The Unix guys basically were the C guys.

I wonder what all the fuss is about. The C language has its problems but as far as I'm concerned break is not one of the bigger ones. It's more of an idiosyncrasy. To my mind, requiring explicit break statements lets you do useful¹ things that would be impossible if there was an implicit break in front of every case (think Duff's Device), and that, together with the fact that this style of switch is fairly straightforward and minimal to implement in a C compiler based on other stuff you already have, may have been enticing to the designers of the language.

Chances are that if you were designing the C programming language from scratch today you would do various things differently, probably including switch statements. But for better or worse, we're stuck with C – at least the C switch statement – as it has been for almost 50 years, so we must remember to put a break in all the appropriate places. If we can get the compiler to remind us to do that if we forgot, or else to tell it explicitly that we didn't want one, that can only be a good thing – ace programmers of rweikusat2's calibre will of course always do the Right Thing™ from the get-go and should therefore not ever be annoyed by superfluous compiler warnings, but people like you and I (and incidentally like jschrod's, my beard is also fairly white by now) may appreciate an occasional heads-up.

¹ Useful, that is, if you think of C as a high-level portable assembly language.


to post comments

Fixing programmers

Posted Mar 15, 2019 18:51 UTC (Fri) by rgmoore (✭ supporter ✭, #75) [Link]

To my mind, requiring explicit break statements lets you do useful¹ things that would be impossible if there was an implicit break in front of every case

You could fix that by allowing an explicit fallthrough when that's what you want. Unfortunately, as you say it's too late to change the syntax now, so the best we can do is use the compiler to catch cases where the break is left out accidentally.


Copyright © 2025, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds