Hacker News new | past | comments | ask | show | jobs | submit login

One thing I would try to do (in addition to the things mentioned in the article) is to delay the introduction of heap allocation and pointers as much as possible, and start with a purely "value based" code style which passes and returns structs by value, especially use C99 features like compound literals and designated initialization. The result is a much saner and 'friendlier' C.

Also ignore the stdlib as much as possible, especially the string functions.

The C stdlib APIs are essentially ancient leftovers from the K&R and early C89 era and should have been modernized when C99 came around. Especially for newbies, paying too much attention to the stdlib may ingrain bad habits.




what should be the replacement for C stdlib?


The stdlib is mostly fine. The string and character classification functions are outdated because they aren't Unicode aware. There's a more detailed write up here [1].

[1] https://nullprogram.com/blog/2023/02/11/


It's not just the missing UNICODE support (although that's probably out of scope for the stdlib, a couple of UTF-8 aware helper functions would be good enough), but footguns-in-waiting like strcpy(), strncpy(), strcat(), strncat(), ...

All the wide string stuff (wchar.h and wctype.h) as well as locale.h is all pointless today.

Everything related to filesystems and file IO is just the bare minimum that's acceptable for simple UNIX-style command line tools, but not really useful in modern applications (most notably, any support for non-blocking IO and memory-mapped-files are missing).

Arguably, complex.h doesn't even belong in the stdlib (I wonder why such an esoteric feature was even considered).

Better support for custom allocation strategies would be nice (e.g. each function which allocates under the hood should accept an allocator argument instead of being hardwired to malloc).

I'm not even asking for a more feature-rich stdlib, a stdlib2 with the obsolete parts removed and modernized IO and memory management functions would go pretty far. But then of course there's the problem that the C stdlib is also accidentially the de-facto system API on some UNIXes.


> any support for non-blocking IO and memory-mapped-files are missing

Sure but POSIX supports that and it may as well be the stdlib for those of us in *nix land.


A new standard C library without unbounded pointers would be a major improvement.

Including a more complete set of common operations (particularly string and vector operations) would be helpful as well.

etc.


There isn't a proper universal solution unfortunately apart from looking for 3rd-party-libs which provide better abstractions over the underlying OS APIs (or writing those yourself).




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: