3 ms·
Ask HN: What extension would you like to see in the next C standard?
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?
- zzo38computer 6y agoI 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.
- marcodiego 6y agoThere is already a sugeestion: http://www.open-std.org/jtc1/sc22/wg14/www/docs/n2592.htm http://www.open-std.org/jtc1/sc22/wg14/www/docs/n2592.htm
- zzo38computer 6y agoYes, I saw the link above; I perhaps should have been more clear in saying so.
- deanmoriarty 6y agoA “defer” statement like in Go. Would remove the need for a bunch of goto.
- marcodiego 6y agoI don't know if it is like in Go, but there is a defer suggestion: http://www.open-std.org/jtc1/sc22/wg14/www/docs/n2589.pdf http://www.open-std.org/jtc1/sc22/wg14/www/docs/n2589.pdf
- stephen82 6y agoI 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-for-c/ https://gustedt.wordpress.com/2020/12/14/a-defer-mechanism-f...
- tjalfi 6y agoI 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.
- krapp 6y agoMultiple 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)
- jaredcnance 6y agoI 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)
- marcodiego 6y agoFor 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.
- zzo38computer 6y agoActually, 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.
- marcodiego 6y agoCan you explain how these goto extensions would work?
- zzo38computer 6y agoOK. 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.