Comment by flandre
2 years ago
> the C standard is horrible. Just about everything is undefined behavior
How is this horrible? This is the core defining feature of C. It is equivalent of saying that a phallic shaped object with a sharp edge is terrible because you may cut/stab yourself and bleed to death, therefore dull equivalent is better (always). This is known as a knife. Knives with extremely sharp blades exist because grinding at the thing you're trying to cut for hours isn't something all of us enjoy. Have you tried not hurting yourself instead before calling it terrible? Sure, one idiot may die because of it, some unlucky guy may get killed with one, but really, I prefer using a real knife when cooking my food and I will never change my mind about that until I die.
> In addition, for large projects, all of the manual namespace management is also a bit of a bore.
When you're writing in C, fun is the least of your worries. I can recommend C++ for big projects, noone but yourself forces use of templates and classes in that department. I can't speak for people writing for controllers made in 1984 with proprietary compilers that probably aren't even maintained anymore, but that's not my problem. For projects like Linux, C++ would be more than sufficient. It's ironic that Rust has been accepted to Linux kernel because what he said about C++ over a decade ago couldn't be more true for Rust aswell, even though all you need to fix that is a bit of discipline, ironic given C programming is practically 99.97% of that.
> One big issue with C is that more or less, the CPU architecture has to treat memory as an array of bytes.
Not relevant, virtual memory is used in practically all modern hardware and "virtual" here means that you have arrays and have no clue what it's truly like already in hardware. Even kernels run in this mode, and all kernel code is written with this expectation. Before you make up such bullshit nonsense, you should tell us about this memory model that's superior to dumb arrays, because until then, noone has ever thought of a better one.
There is the classic case of the Linux kernel dereferencing a null point and then check if it is null. Then the compiler removed the null pointer check because dereferencing a pointer means that it cannot be null without invoking undefined behavior.
This is just horrible. C started out as portable assembler. Now essential instructions get deleted. The C standard is a horrible way to define a low-level programming language. Obviously, C is a sharp object. But standard C is a sharp object that jumps at you.
I had a lot of fun writing C. The same way you can have fun writing assembler or do other level stuff. Compared to low-level kernel stuff, C is not a big problem.
I'm talking radically different architectures. Virtual memory has a high cost in the implementation of a CPU. There could be other architectures, capability based, segment based, etc. But if your CPU has to run C efficiently, then you probably don't want to go there.
There is a lot of cruft, like ASLR, that only exists because memory is a flat array of bytes.
As long as the primary goal of a CPU is to run C efficiently, we won't get beyond paged virtual memory.