I cannot write an abstraction in C, which closes a file handle automatically. That is what the author complains about. In C++ you can do that.
Re:Why the C Programming Language Sucks
by EmanueleAina on Friday August 21, 2015 @10:39AM
(#10097742)
To some extents, it depends on the definition of C: by the standard, you're right, you can't. But with some relatively common (GCC and clang) extension (ie. __attribute__((cleanup))) you definitely can, see g_autoptr() from GLib for an easy way to use it: https://blogs.gnome.org/desrt/2015/01/30/g_autoptr/
> I cannot write an abstraction in C, which closes a file handle automatically.
Of course you can.
It's just a question of convenience, and whether the resulting style would align with idiomatic C. In my imagined implementation, it would look more like awkward JavaScript.
There are many many C codebases that are internally consistent but don't look much like textbook C. Sometimes C is the best choice even when it's less convenient.
C is an abstraction of a system. It has memory, file handles, and other things that a system has. That's why people write OSes in C. When you're writing an OS, what are you doing other than managing a resource? The 1/2/3 are necessary when they are the whole point of the language.
Of course it sucks to write something like a website in C when you can use a high level language like Python which has libraries containing plausible abstractions for web pages.