News for hackers. Stuff that matters.

Ask HN: What would you tweak in C to make it a nicer language?

If you could tweak C without adding huge new features (like OO or changing paradigm), what would your changes be?

examples: Zero initialized memory. Improved function pointer syntax. Remove '->' and replace with '.'. Array bounds checking. Standard inline assembly syntax. etc. etc. (There are probably a lot I haven't thought about)

( 12 comments | 6 points | on HN )
Re:Ask HN: What would you tweak in C to make it a nicer lang... by angersock on Friday August 29, 2014 @01:40AM (#8241292)
Some handy little things:

1. Standard library support for safe arithmetic (easily capturing overflows, underflows, and so forth).

2. Standard library support for threading and synchronization primitives.

3. Mandated tail-call optimization through pragmas or perhaps just requiring it in the spec.

4. Create explicit and differentiated arithmetic and logical shift left and shift right.

5. Add a standard way of specifying arbitrarily-sized integers (with optimization for the common word sizes).

6. Add destructuring operations.

7. Add anonymous unions.

8. Add switching on strings in switch statements.

9. Add proper UTF8 support.

10. Add a slab allocator to the standard library.

11. Add regexes to the standard library (possible as a language feature).

~

Several of these (7, for example) are being addressed in C11 (if that ever comes out).

Re:Ask HN: What would you tweak in C to make it a nicer lang... by sharth on Tuesday September 02, 2014 @08:57AM (#8257224)
I'm confused by "if that ever comes out". C11 was released 3 years ago.
Re:Ask HN: What would you tweak in C to make it a nicer lang... by andrewchambers on Friday August 29, 2014 @02:36AM (#8241383)
These are all great.
Re:Ask HN: What would you tweak in C to make it a nicer lang... by J_Darnley on Friday August 29, 2014 @11:53AM (#8243048)
Make everyone use C99 standard integers for various data types so that people can stop trying to "detect" what type to use in a horrible autotools script.
Re:Ask HN: What would you tweak in C to make it a nicer lang... by MalcolmDiggs on Friday August 29, 2014 @01:56AM (#8241318)
Most of my pain-points with C were solved with syntactic-sugar libraries like Cello (http://libcello.org/).
Re:Ask HN: What would you tweak in C to make it a nicer lang... by darsenault on Tuesday September 02, 2014 @02:49PM (#8259389)
What are some other libraries, like libCello, that help with c in syntactic-sugary ways?
Re:Ask HN: What would you tweak in C to make it a nicer lang... by sunny1304 on Friday August 29, 2014 @01:26AM (#8241263)
I want generic programming like Rust.
Re:Ask HN: What would you tweak in C to make it a nicer lang... by mc_hammer on Friday August 29, 2014 @01:08AM (#8241222)
i would make it coffeescript like syntax and add in underscorejs functionality -_-
Re:Ask HN: What would you tweak in C to make it a nicer lang... by adamnemecek on Friday August 29, 2014 @12:44AM (#8241162)
Probably a legit macro system.
Re:Ask HN: What would you tweak in C to make it a nicer lang... by andrewchambers on Friday August 29, 2014 @12:47AM (#8241170)
Any ideas on how it should look? Perhaps there are good examples in non lisp languages which have good systems, though i haven't tried them to know which is good.
Re:Ask HN: What would you tweak in C to make it a nicer lang... by adamnemecek on Friday August 29, 2014 @12:49AM (#8241174)
I don't have much experience with it but Rust's seems to be pretty good.
Re:Ask HN: What would you tweak in C to make it a nicer lang... by J_Darnley on Saturday August 30, 2014 @11:46AM (#8246710)
My personal suggestion would be to borrow the nasm/yasm pre-processor. x264 has certainly used it to great effect.