(I'm exaggerating; of course I know why people still write things in C, but I would have a hard time justifying starting a new project in C these days.)
(I'm exaggerating; of course I know why people still write things in C, but I would have a hard time justifying starting a new project in C these days.)
Portability might be the most reasonable argument, which is understandable when you're writing things like build systems, e.g.:
https://git.sr.ht/~lattis/muon
Then there are small tools when using anything else just doesn't buy you much, and if you're familiar with C, why bother? e.g.
https://git.sr.ht/~kennylevinsen/wlsunset
And situations like this one where you need both C API (for maximum compatibility), and manual memory management is a much for various reasons (read the blog post)
How does it continue? Assembly=walking, fixie=C, regular bike=fortran, electrically assisted bike=C++, electric wheelchair=python, ...
:_D You made my day! I'd continue like this: barely moving eye-popping-graffiti-painted squeaky wheelchair with no bearings mounted with duck tape inside a rusty sea container, that is chained to a heavy truck with broken exhaust and flat tires = (you guessed it! :) )
If you add a solid rocket booster to this contraption (so that it actually moves) that would be exactly javascript.
It is alot easier to reason about performance. The code does somewhat translate to the machine instructions you anticipate.
But the greatest advantage is all the fancy pants idioms you don't feel compelled to use.
Life is too short to waste time tracking down double frees, out-of-bounds writes, memory leaks, and weird concurrency issues.
However this is hardly going to change outside the domains where corporations push for blessed languages on their platform SDKs, people keep being educated that C maps 1:1 to Assembly language and thus the myth continues.
Even Microsoft with all their security talk only allows on Azure Sphere OS and Azure RTOS, the reasoning being their target market doesn't wan't anything else.
What's the objection there? I want the state to be freed when the object's lifetime ends. For something only needed during a function, a local value variable makes sense. For something that needs to last longer, either give it a move operator, or put it on the heap and use unique_ptr.
If your point is that people sometimes use unique_ptr<std::string> instead of std::string or std::optional<std::string>, then yeah I agree, that's generally not good.
In my C firmware projects I do not allocate memory at all. Everything is predetermined.
Having said that, "delete" hardly showed up at all.
On desktops / servers I prefer other languages and would not want to mess with C, at least for the types of products I do.
Window managers don't do all that much most of the time; I bet you could even write one in Python and not see performance issues. Hell, Go would be more than performant enough.
And energy efficiency?