from Hacker News

C is not just a bad language

by matesz on 2/14/24, 9:30 PM with 2 comments

  • by dswilkerson on 2/14/24, 10:21 PM

    "v later found out with more debugging that it happened because the module in question cast that struct back from memory, and then added its own stuff to it."

    That's your problem right there: "cast". In C, you can cast things, but doing so breaks the type system, which can no longer help you. That's not the fault of C, that's your fault. You literally asked for it.

    C is the useful idioms of assembly language made first-class. For fundamental reasons of the universe, C is the programming language. See also: https://embeddedgurus.com/barr-code/2018/02/c-the-immortal-p...

    "This year a portion of my analysis is focused on multi-year trends. One trend that really stands out to me is that the C programming language refuses to give up the ghost.

    "A longitudinal study of survey data spanning almost a decade and a half shows that C remains the primary programming language of embedded software. Remarkably, in that time C has actually gained market share from 50% to about 70%–at the expense of assembly, C++, and Java."

  • by paulrpotts on 2/14/24, 11:54 PM

    It's a funny dunk on the language but I was hoping for some actual root cause analysis. It sounds like the change actually uncovered a pre-existing bug which was not (yet) causing a crash (but may have been silently overwriting memory). In that case, the root cause was the existing code's failure to use memory safely. There's not much point blaming a 50-year-old language, which was never designed with modern type safety but instead has features that allow deliberately throwing away safety to make low-level systems programming possible, for not having modern type safety. The generation of programmers who learned to use it as safely as possible (which I belong to) are getting old and cranky. We're now inclined to say that the person who wrote the pre-existing bug needed more experience. We'd all love to use Rust for new code but there's an awful lot of legacy C code that needs fixing.