
Ask HN: What could an alternative to the C standard library look like? - jakogut
My understanding of compiler history is that before the C standard, compiler
vendors created their own C libraries that shipped with their compilers. Code
written to be compiled with one compiler likely would not work without
modification using another compiler.<p>The C standard obviated this portability problem, and arguably standardized
problems of its own. Functionality that became standardized, such as strcpy and
scanf, now considered unsafe and best avoided, is retained for backwards
compatibility. Some functions, such as strtok, modify static buffers and are not
re-entrant. Manual memory management is still du jour, without any standardized
alternatives such as an interface for reference counting.<p>The C standard also lacks implementations of common data structures and
algorithms, which keeps the language light and easy to learn, at the cost of
often needing to reinvent the wheel.<p>C isn&#x27;t going anywhere. Many lament the unsafety of the language, and for good
reason. However, it&#x27;s often the lowest common denominator in ABI compatibility.
The performance and explicitness of C is unparalleled in a lot of tasks. At the
same time, it&#x27;s rather easy to disable the standard library during compilation,
and link to a different one.<p>I&#x27;ve been wondering for a while, has anyone recently (or ever) attempted to
create a competing C standard, or language based on C with only a different
standard library? What are the pros and cons of such a project? If you could
start fresh on the standard library, could a modern perspective and different
design choices yield a better language? How different could the result look?
Has something similar ever been done with any other language?
======
7786655
I would not add common data structures or an interface for reference counting.
C has no generics so there is no good way to implement these. You could use
macros, but that would be abominable. You could use void* , but that leaves a
lot of performance on the table (see: qsort, bsearch).

What I would do is purge null-terminated strings from the standard library and
use exclusively pointer-and-length strings. (const char * str, size_t
str_len). That would be a massive improvement, especially to the IO library,
which currently has to support both null-terminated strings and pointer-length
strings (since only the latter allows binary IO).

The C locale library is really awful. printf() needs to have a way to choose
between locale-dependent and locale-independent formats, and the latter should
be the default.

strcmp(), strcpy(), and strcat() would all be gone because without null-
terminated strings these can be replaced by memcmp() and memcpy().

It would also be nice if the IO library allowed creating memory-backed files,
since this is a very common extension and would make FILE * more useful for
defining APIs that take or output to streams.

Would add a standard interface for getting a directory listing.

Make char unsigned by default. (Currently it's implementation dependent, and
usually signed, which is almost always incorrect).

And I would get rid of isupper() and other functions that can't handle
multibyte characters.

