by zik · 6y ago · 0 comments
A huge advantage of C that most people seem to forget these days is that it's quite a minimalist language by today's standards so it's relatively easy to learn and reason about.
But maybe the most compelling advantage is that its underlying architectural concepts map well to most real-life CPUs so it's a much better basis for compilers to generate efficient code than many languages. This is a subtly different thing from being "close to the metal". It's really more like "has compatible design concepts with CPUs". The abstract machine of C has relatively few gotchas when converting to machine code and that's what it's really about.
That doesn't mean that C's the "high level assembler" people speak about though. It's not. Take a look at some optimised assembler output from a C compiler and you'll see that's patently not true. It can be very difficult to even understand how the C source code relates to the generated assembler code - often you'll see that none of the same operations occur and nothing happens in the same order.
...can easily happen indeliberately. Just as any other exceptions. Which C can't even handle in a deterministic way because it doesn't have built-in exceptions, so you have to rely on libraries or remembering to check error codes. Not easy to reason about.
> typing is a non-issue
When all your function ptrs have to be cast to and from (void*) - hell yeah it's an issue.
> minor hassle
Then why are buffer overflow exploits in C programs on the news?
I don't know how you got this impression. This is 100% incorrect.