Most active commenters
  • bboygravity(3)
  • flohofwoe(3)
  • pjmlp(3)

←back to thread

The C23 edition of Modern C

(gustedt.wordpress.com)
515 points bwidlar | 23 comments | | HN request time: 1.75s | source | bottom
1. israrkhan ◴[] No.41855279[source]
Most important aspect of C is its portability. From small microcontrollers to almost any computing platform. I doubt that any new version of C will see that much adoption.

If I want to live on cutting edge I would rather use C++2x or Rust rather than C.

Am I missing something? What benefit this supposedly modern C offers?

replies(7): >>41855343 #>>41855410 #>>41855595 #>>41855880 #>>41856401 #>>41858691 #>>41860058 #
2. vitaminka ◴[] No.41855343[source]
these features will eventually trickle down into the mainstream, kind of like C11 is doing at the moment

also, unless you're targeting embedded or a very wide set of architectures, there's no reason why you couldn't start using C23 today

replies(1): >>41855853 #
3. ◴[] No.41855410[source]
4. doe_eyes ◴[] No.41855595[source]
Of course they will, just like they did in the past with C11, GNU extensions, or some of the individual features that are now rolled into C23. For example, the 0b notation for binary numbers is widely used in the MCU world.

The microcontroller toolchains are generally built on top of GCC, so they get the features for free. There are some proprietary C compilers that are chronically lagging behind, but they are not nearly as important as they used to be two decades ago.

5. bboygravity ◴[] No.41855853[source]
Or in other words, for embedded and existing code: most use c99, some use c11 and nobody uses c23 until at least 10 years from now.
replies(2): >>41855978 #>>41855982 #
6. shakna ◴[] No.41855880[source]
The `thread_local` specifier is used on a few microcontroller platforms already, but would be absolutely illegal in C11 and before to use. However, it vastly simplifies memory management in a threaded context.

Why would I rather step into the world of C++ just to deal with that?

replies(1): >>41857253 #
7. dhhfss ◴[] No.41855978{3}[source]
This depends on the platform. Many embedded systems are based on arm these days and have modern toolchains available.

I cannot remember the last time I saw C99 used. C codebases generally use C11 or C17, and C++ code bases use C++20

replies(2): >>41856523 #>>41886801 #
8. vitaminka ◴[] No.41855982{3}[source]
most non-embedded and non-legacy codebases could use c23, that's not an insignificant set
replies(1): >>41886816 #
9. flohofwoe ◴[] No.41856401[source]
One advantage of writing C code is that you don't have annoying discussions about what idiomatic code is supposed to look like, and what language subset is the right one ;)

For the cutting edge I would recommend Zig btw, much less language complexity than both modern C++ and Rust.

One good but less visible side effect of C23 is that it harmonizes more syntax with C++ (like ... = {} vs {0}) which makes it a bit less annoying for us C library maintainers to support the people how want to compile their C code with a C++ compiler.

replies(2): >>41856506 #>>41858603 #
10. pjmlp ◴[] No.41856506[source]
There is enough material in C, and related compiler extensions, to have similar discussions, starting from where to place brackets.
replies(1): >>41862159 #
11. pjmlp ◴[] No.41856523{4}[source]
Unless you can vouch for the C++ compiler, the best C++ portable code can offer today is C++17.

Also 8 and 16 bit embedded toolchains are certainly not on C11 / C17, they can hardly afford full C89.

replies(1): >>41857834 #
12. casenmgreen ◴[] No.41857253[source]
IIRC, performance and cost of thread local store varies greatly between platforms.

You have to know what you're biting into, before you use that.

13. flohofwoe ◴[] No.41857834{5}[source]
SDCC is a niche C compiler for 8-bit CPUs and is more uptodate than MSVC ;P

https://sdcc.sourceforge.net/

That's the nice thing with C: it's much easier for small teams to fully support than the latest C++ standards.

replies(1): >>41859229 #
14. Arch-TK ◴[] No.41858603[source]
> C library maintainers to support the people how want to compile their C code with a C++ compiler.

Just tell them to go away.

Trying to write the subset of C and C++ is a fool's errand.

replies(1): >>41860015 #
15. pragma_x ◴[] No.41858691[source]
I'm with you on this. The feature list reads like a subset of later C++ standards that fit within C's (deliberately) rudimentary feature set.

You could, in theory, just use C++ and be done with it. But like any C++ project you'd need a pretty strict style guide or even a linter, but this time it would have to be extra restrictive lest you slide into full C++ territory. And maybe that's a major stumbling block for some people?

16. pjmlp ◴[] No.41859229{6}[source]
Now try to use it on the embedded deployments that require certification.
17. jstarks ◴[] No.41860015{3}[source]
No inline functions in library headers, then.
replies(1): >>41860766 #
18. BenjiWiebe ◴[] No.41860058[source]
Won't any llvm/gcc supported target get the new version of C automatically? You won't get it in the vendor-modified ancient gcc toolchain for some other arch though.
replies(1): >>41875088 #
19. flohofwoe ◴[] No.41860766{4}[source]
Inline is mostly pointless in C anyway though.

But it might be a minor problem for STB-style header libraries.

It's not uncommon for C++ projects to include the implementation of an STB-style header into a C++ source file instead of 'isolating' them in a C source file. That's about the only reason why I still support the common C/C++ subset in my C libraries.

20. rbanffy ◴[] No.41862159{3}[source]
Maybe the C24 will define the One Right Way.
21. israrkhan ◴[] No.41875088[source]
There are many embedded platforms that do not gcc/llvm based compilers.

Also most companies making those platforms are not good at updating their toolchains. Expecting developers to compile their own toolchain, that is unsupported by platform vendor, is too much to ask.

Also GCC dropped support for certain architectures along the way, and even if you are willing to compile your own toolchain, it may not work for you.

22. bboygravity ◴[] No.41886801{4}[source]
Most devices that are 6+ years old (as far as I can tell) use C99. If not C89. And/or C++17, if that.

That's A LOT of devices out there. A lot of which still get maintenance and even get feature updates (I'm working on one right now, C99).

So the claim that "C codebases generally use C11 or C17, and C++ code bases use C++20" intuitively sounds like totally untrue to someone working in embedded C/C++. I've been doing this for 15+ years and I've never touched anything higher than C99 or C++17.

If you're talking about gaming, sure. But that's not "C code bases generally".

23. bboygravity ◴[] No.41886816{4}[source]
I would argue that is an insignificant set.

Unless you think that code-bases created in the past year are a significant part of code bases that have been created since the inception of humanity.