News for hackers. Stuff that matters.
Re:C23: A Slightly Better C by mgaunard on Sunday January 21, 2024 @02:54PM (#39082325)
C++ is already a better C.

So much so that new revisions of C are just backporting features at this point.

Re:C23: A Slightly Better C by janice1999 on Sunday January 21, 2024 @03:03PM (#39082420)
C++ is a better C in the same way that a Cybertruck is a better bicycle.
Re:C23: A Slightly Better C by tyree731 on Sunday January 21, 2024 @03:42PM (#39082838)
Nah. More like C is a bunch of hand tools, and C++ is those same hand tools, plus a bunch of power tools. Sure, you could just use the hand tools, and hey maybe they even give you a better of sense of what you’re building at a low level, but it’s exhausting, and it turns out the power tools are really useful.
Re:C23: A Slightly Better C by janice1999 on Sunday January 21, 2024 @03:46PM (#39082871)
Some of C++ features are great, as recently discussed on the Linux kernel mailing list. However for many of Cs usecases, they are not appropriate, like exceptions and RAII in embedded. Once you start disabling major features those 'power tools' become far less attractive. Also, to extend the metaphor, hand tools are usually obvious and easy to use while power tools can have very long manuals. See for example the 275 page book on just Initilisation in C++ [0].

[0] https://www.cppstories.com/2022/cpp-init-book/

Re:C23: A Slightly Better C by spacechild1 on Sunday January 21, 2024 @04:39PM (#39083343)
How is RAII a problem on embedded platforms? It is basically about scoped cleanup, something you would otherwise have to do manually.
Re:C23: A Slightly Better C by actionfromafar on Monday January 22, 2024 @07:41AM (#39088854)
Not sure what waa meant but what comes to mind to me who has dabbled in embedded is that in C it’s painfully clear how long “objects” live and when you tear them down and how. In C++ stuff can easily “happen” at an inopportune moment.
Re:C23: A Slightly Better C by mgaunard on Monday January 22, 2024 @09:45AM (#39090009)
Same in C++: happens at the end of the scope. You precisely control where that is.
Re:C23: A Slightly Better C by PaulDavisThe1st on Sunday January 21, 2024 @03:26PM (#39082682)
funny, but false.

the only sense in which the relationship between C & C++ is like that of a cybertruck to a bicycle is the one in which the latter are "transportation devices" and the former are "programming languages". there is no particular feature of a bicycle represented by a cybertruck other than "it gets you somewhere".

Re:C23: A Slightly Better C by janice1999 on Sunday January 21, 2024 @03:39PM (#39082809)
Yes, that's literally the point I was making.
Re:C23: A Slightly Better C by PaulDavisThe1st on Sunday January 21, 2024 @04:52PM (#39083457)
Sure, but it's wrong. There's a ton of features of C present in C++. You might not like the C++ context they are present in, but it's nothing at all like the cybertruck/bicycle (non)relationship.
Re:C23: A Slightly Better C by pjmlp on Sunday January 21, 2024 @04:50PM (#39083440)
I guess some people are happy with a macro Assembler with a better syntax than MASM/TASM/NASM/yasm high level macros.
Re:C23: A Slightly Better C by z_open on Sunday January 21, 2024 @02:57PM (#39082359)
C++ and C are no longer used for the same types of projects so C++ is not a better C.
Re:C23: A Slightly Better C by mgaunard on Sunday January 21, 2024 @03:11PM (#39082520)
I think you must be from the 90s -- if so can you share your time machine?

All kinds of major projects switched to C++ already, for example GCC. All the major new projects, for example LLVM, are also in C++ from the get-go.

Even the Linux kernel is considering switching to C++ now.

Re:C23: A Slightly Better C by leosanchez on Sunday January 21, 2024 @03:15PM (#39082563)
> Even the Linux kernel is considering switching to C++ now.

Source?

Re:C23: A Slightly Better C by mgaunard on Sunday January 21, 2024 @03:20PM (#39082623)
Re:C23: A Slightly Better C by kleiba on Sunday January 21, 2024 @03:31PM (#39082724)
I wonder if Linus has changed his views on C++ too in the mean time.

http://harmful.cat-v.org/software/c++/linus

Re:C23: A Slightly Better C by franzb on Sunday January 21, 2024 @03:22PM (#39082645)
Re:C23: A Slightly Better C by rzzzt on Sunday January 21, 2024 @03:19PM (#39082617)
A weird way to spell "Rust".
Re:C23: A Slightly Better C by mgaunard on Sunday January 21, 2024 @03:21PM (#39082631)
I giggled -- thank you.
Re:C23: A Slightly Better C by liquid153 on Sunday January 21, 2024 @03:17PM (#39082587)
No they’re not
Re:C23: A Slightly Better C by riku_iki on Sunday January 21, 2024 @03:32PM (#39082738)
> Even the Linux kernel is considering switching to C++ now.

considering doesn't mean it will happen in near future, because toolchains/ecosystem is not there, the same is applicable for many other projects.

Re:C23: A Slightly Better C by mgaunard on Sunday January 21, 2024 @04:35PM (#39083311)
I'm not aware of any toolchain limitations; making the kernel compile as C++ is doable with a few trivial patches, and the kernel already is heavily GCC-specific, which supports both C and C++ to the same level.
Re:C23: A Slightly Better C by riku_iki on Sunday January 21, 2024 @04:38PM (#39083340)
software is complex, and you can't be sure until you run it in mission critical production.
Re:C23: A Slightly Better C by mgaunard on Monday January 22, 2024 @03:07AM (#39087399)
With the same argument you couldn't upgrade the compiler at all.

Thankfully the Linux kernel development relies on testing instead.

Re:C23: A Slightly Better C by EasyMark on Sunday January 21, 2024 @08:45PM (#39085094)
I have my doubts on c++ ever making it into the mainstream kernel while Torvalds is benevolent dictator. Especially since there is rust. I agree with the rest of what you said though.
Re:C23: A Slightly Better C by pjmlp on Sunday January 21, 2024 @03:02PM (#39082415)
Until C fixes its string and array story, C++ keeps being a better C.
Re:C23: A Slightly Better C by cyberpunk on Sunday January 21, 2024 @04:12PM (#39083119)
I just use bstrlib... It's solid and works perfectly..
Re:C23: A Slightly Better C by pjmlp on Sunday January 21, 2024 @04:51PM (#39083445)
It is not part of ISO C and that is a big difference.
Re:C23: A Slightly Better C by Xeamek on Sunday January 21, 2024 @03:39PM (#39082806)
'just backporting [good] features' doesn't sound that bad when c++ is widely considered the most bloated mixture of the good, the bad and the ugly that there is.

Maybe the c++ killer will turn out to be just some future, modern version of C...

Re:C23: A Slightly Better C by bluetomcat on Sunday January 21, 2024 @03:39PM (#39082808)
C++ is a different animal of a language. It is about compile-time meta-abstractions that generate a ton of invisible code under your feet. It has complex expression semantics and a crowded syntax space.
Re:C23: A Slightly Better C by akira2501 on Sunday January 21, 2024 @04:11PM (#39083103)
> that generate a ton of invisible code under your feet

Which is bad enough but there are plenty of cases where it may do this, or it may generate short obvious sequences of code, depending on more factors like compiler flags than you can easily observe while examining the line of code in question.

Hence the "as-if" rule, which helpfully applies in a lot of places, but not all, like return value optimization. I never felt like taking the time to build the kind of C++ confidence one must require to wield it correctly.

Re:C23: A Slightly Better C by EasyMark on Sunday January 21, 2024 @08:43PM (#39085081)
but this post is about c++ 23 and probably should stay on that topic? Everyone who uses c knows you can do it in c++ but either don't want to introduce the extra complexities, work with older code bases, prefer the "simplicity" of c, or have an organizational requirement. Personally on embedded I like c++, especially raii, smart pointers, containers, and classes, but I completely avoid rtti, exceptions, and complex template metaprogramming (by me). That subset is easy to keep in my head and on my projects. However some clients want C, and that's what I give them.