News for hackers. Stuff that matters.
Re:New C features in GCC 13 by frde on Thursday May 04, 2023 @08:11AM (#35814098)
I guess my question is: If you want `auto`, why put it in C instead of using C++ with no other C++ specific feature besides auto?

I get people don't like classes / templates / .. but there isn't any reason one has to use those.

Re:New C features in GCC 13 by masklinn on Thursday May 04, 2023 @08:16AM (#35814134)
> I guess my question is: If you want `auto`, why put it in C instead of using C++ with no other C++ specific feature besides auto?

Because they're orthogonal, and making function bodies less verbose with no loss of expressivity is nice, without needing to significantly alter the language?

Pretty much every C competitor has local type inference, and C actually needs more than most due to the `struct` namespace, typing `struct Foo` everywhere is annoying, and needing to typedef everything to avoid it is ugly.

Also C++ is missing convenient C features, like not needing to cast `void*` pointers, and designated initialisers were only added in C++20.

Re:New C features in GCC 13 by pmarin on Thursday May 04, 2023 @08:40AM (#35814337)
Type inference only make the code harder to read. You ended doing mental compiler work when you could just write the damm type.

And the people who say "I Just hover the variable in my IDE" It doesn't work in a terminal with grep, you can't hoved a diff file and not even github do the hover thing.

Combine that with the implicit type promotio rules of C. Have Fun.

Re:New C features in GCC 13 by masklinn on Thursday May 04, 2023 @08:44AM (#35814382)
> Type inference only make the code harder to read.

Nonsense.

> Combine that with the implicit type promotio rules of C. Have Fun.

This sort of trivial TI does not make that any worse. C is broken, it neither breaks nor unbreaks C.

Re:New C features in GCC 13 by hgs3 on Thursday May 04, 2023 @09:12AM (#35814727)
typeof and auto are useful for writing type-generic macros.
Re:New C features in GCC 13 by pmarin on Thursday May 04, 2023 @10:55AM (#35816343)
Yeah but looking how auto has been abused in C++ I don't think it worth it.
Re:New C features in GCC 13 by peterfirefly on Thursday May 04, 2023 @11:13AM (#35816658)
C23's auto is not nearly as magic as C++'s auto. You can use it for the simple things but not for the perversely creative abuse scenarios you fear.
Re:New C features in GCC 13 by circuit10 on Thursday May 04, 2023 @08:16AM (#35814139)
I guess one possible reason is if there’s no C++ compiler for an obscure platform as it would be too much work, but there is an up-to-date C compiler
Re:New C features in GCC 13 by klodolph on Thursday May 04, 2023 @09:55AM (#35815373)
Yeah, seems like half of the embedded architectures are like this. Well, the C compiler is not quite standards compliant, and often made to an older version of the C spec, but give it time—the C2x standard comes out this year, and it may not benefit people in the embedded space until some years down the road.

Second-best time to plant a tree, and all.

Re:New C features in GCC 13 by klodolph on Thursday May 04, 2023 @09:52AM (#35815338)
You end up having to turn a lot of C++ features off in order to get the experience you want in certain environments. In an application running on a modern Windows/Linux/Mac system, it’s no big deal to use those features.

Some platforms also just don’t have C++ compilers. Yes, they still exist. You buy some microcontroller, download an IDE from the manufacturer's web site, and you get some version of C with a couple extensions to it. And then there are all the random incompatibilities between C and C++, where C code doesn’t compile as C++, or gives you a different result.

Re:New C features in GCC 13 by jcelerier on Thursday May 04, 2023 @10:12AM (#35815630)
What's "a lot of features" ? -fno-rtti, -fno-exceptions?

> Some platforms also just don’t have C++ compilers

It's not like they're going to have C23 compilers either

Re:New C features in GCC 13 by flohofwoe on Thursday May 04, 2023 @10:33AM (#35815992)
> It's not like they're going to have C23 compilers either

Niche compilers like SDCC (https://sdcc.sourceforge.net/) are actually keeping track of recent C language improvements quite well.

Re:New C features in GCC 13 by klodolph on Thursday May 04, 2023 @10:24AM (#35815843)
C++ has a lot of funny rules when it comes to constructors and initializers. It's easy to accidentally to do something unintended, and end up with code that relies on initialization order.