Ask HN: What extension would you like to see in the next C standard?

5 points by marcodiego ↗ HN
There are some interesting new proposals for what will likely become c23. Some I like: - true and false as first-class language features: http://www.open-std.org/jtc1/sc22/wg14/www/docs/n2655.pdf - a fundamental type for N-bit integers: http://www.open-std.org/jtc1/sc22/wg14/www/docs/n2646.pdf - auto, closures and lambdas: http://www.open-std.org/jtc1/sc22/wg14/www/docs/n2638.pdf - preprocessor embed to include binary files: http://www.open-std.org/jtc1/sc22/wg14/www/docs/n2592.htm - typeof: http://www.open-std.org/jtc1/sc22/wg14/www/docs/n2593.htm - defer: http://www.open-std.org/jtc1/sc22/wg14/www/docs/n2542.pdf

What else would you like to see in the next revision of the C programming language?

13 comments

[ 4.1 ms ] story [ 39.0 ms ] thread
I would like to see some of the features that GNU C has, such as zero-length arrays, typeof (which you mentioned there already), fopencookie, etc. A preprocessor command to include binary files is also a feature I thought of wanting in C, so it is good if they will add that too.
A “defer” statement like in Go. Would remove the need for a bunch of goto.
I think "defer" is coming [1], along with other goodies that simplified the life of C++ developers, but time will tell.

I really hope they approve the following:

    * auto
    * constexpr
    * lambda function
    * __typeof__ used as typeof; it behaves like decltype
It would lead to cleaner code without excessive macro magic; only where would be needed.

[1] https://gustedt.wordpress.com/2020/12/14/a-defer-mechanism-f...

I would prefer if the committee devoted their efforts to making C easier to use correctly - defining undefined or implementation defined behavior, requiring stronger diagnostics, and forbidding optimizations that regularly cause issues.
Multiple returns. I've always thought just adding pointer params was kind of an ugly hack.

Function overloading and default parameters. They're just too nice not to have.

Closures and lambdas (mentioned)

I want to ask this question here because I feel like many of the viewers will be proponents of C and I want to hear your perspective. Why would someone choose C as a language of choice for a new project over Rust (or some other comparable language with memory safety guarantees)? Will/can C ever address the memory safety issues?

(I’m looking for honest dialogue and not trying to be combative)

For embedded, system software, drivers and kernel work C is probably still king. Also, C is simple and popular enough for one to understand entirely, some people simply prefer it.
Actually, I can think of some more:

- "goto case" and "goto default"

- Using ?: with nothing in between, like GNU C does. This is a feature I often use.

Can you explain how these goto extensions would work?
OK.

This goto case extension would be, if you write "goto default" inside of a switch block, then it go to the default label, and if you write "goto case" and an expression, it evaluate the expression and go to the case label that matches the result, or to default if there isn't a match.

The ?: with nothing in between is documented in the GNU documentation, although I can also explain here: If whatever is before the question mark is true then that value is used (without evaluating it twice); if false, then instead whatever is after the colon will be used.