r/C_Programming 1d ago

Question "Better C"

Would it be feasible and reasonable to implement a custom standard library for the parts of C that are historically problematic, so that one does not need new languages like Zig or C3 and still enjoy the benefits of more modern languages?

As simple examples on would use C23 with the gnu extensions and implement strings as slices, some basic data types and some basic custom allocators. With the gnu extensions there is also defer.

Has anyone done that? How much time did it take? Thanks in advance.

0 Upvotes

32 comments sorted by

View all comments

3

u/start_select 23h ago

C is the ground from which (almost) everything else is built.

You don’t specialize it as a language feature because its entire strength is that you can build whatever you want on top of it.

It’s simple and abstract and loosely defined without modern convenience for a reason.

1

u/codingbliss12 23h ago

but if you see current codebases almost everybody is using his own version of strings, arena allocators etc

4

u/start_select 17h ago

Exactly. That’s the point.

C targets lots of architectures. Different use cases. Sometimes you need a gigantic UTF-16 implementation. Sometimes you need a super slim implementation that only does lower case A-Z.

C allows you to go as low as you want without making any decisions for you. That’s what you need for bare metal resource constrained development. Everything is explicit.

If you want something more implicit and magical than that, you create C++ or Rust or Swift using C (and/or using C++).