by dottedmag · 4y ago · 0 comments
Not the pervasive undefined behaviour and compilers that become more aggressive every release about breaking previously-working code?
Not the reams of code that assume sizes of integers and signedness of char?
Not the wild build process that makes it awfully hard to actually build anything that has any dependencies whatsoever.
strtol. Damn, what a nuisance!
As a place to start discussing why a successor systems language is necessary, comparing string parsing across Rust, Zig, and C? Pretty good place to start, because the problems it introduces are pervasive as the discussion continues.
Magic error values that get globally mutated? Check. Pointers which are either null or exist so you can do arithmetic to deduce a byte length? Check. An almost aggressive distain for handling sum types of even the simplest sort? Check.
Turns out Zig and Rust are whupping the ol' llama on undefined behavior and build processes as well, not to mention memory safety. If only this author had indicated that they might continue writing on the subject...
Even if these functions disappeared overnight and C acquired the standard library redone using the knowledge accumulated over years, it would not make a difference:
- C is a disaster to write any amount of code in due to the definition of undefined behaviour in the specification.
Not only compilers are free to do anything they want with code that exhibits undefined behaviour, they are unable even to detect undefined behaviour in the code, and hence the only way to write reliable code is to freeze your compiler, toolchain and target OSes: any minor change in any of components (including OS headers) may completely ruin your program.
Ask Linux folks who were bitten by it many times, even though do not have to deal with garbage in vendors' OS headers.
- C is a disaster due to its compilation model. Preprocessor defines wreak havoc on the source code, and it is a backbreaking job to maintain cross-compilability of any large-ish codebase. Forget about trying to cross-compile the whole software with dependencies: this is a full-time job by itself.
- C does not specify sizes of short, int, long and signedness of char. This means any codebase that ever touches these types (and there are OS interfaces that are expressed in them!) is inherently non-portable: every new target means combing over the whole codebase and checking breakages in all arithmetic operations.
There are other underspecified pieces in spec, but this one is just the most salient one.
> in production and teaching
If a teaching resource does not state "C spec has undefined behaviour, and you will have a very bad time if you don't know about it", then it's utter garbage.
In your opinion. It may surprise you to know, others might have differing opinions.
At least from how I read it, I completely agree with the post. C makes it hard for programmers to write safe code in general and the author was pointing out one example of this behaviour and what causes it.
Show me the large-ish (100K+ LOC) codebase with dependencies that can be cross-compiled, does not come with tons of cruft like autoconf or Meson, and does not require installing reams of software on the host as "libraries", and then we are talking.
(edited: typo)
So, where's the link to a modern C project that is a breeze to work with? Requirements are in the parent comment.