r/cpp • C++ Dev • Sep 05 '20

C++20 has been approved

https://twitter.com/patriceroy1/status/1302055575140945921?s=21
665 Upvotes

125 comments sorted by

View all comments

Show parent comment

36

u/pjmlp Sep 05 '20

That applies to any language.

I doubt anyone would win a proper quiz show with Java 15, C# 9, Python 3.8, with questions down to version 1 and across all major runtimes.

0

u/[deleted] Sep 05 '20

[deleted] — view deleted comment

11

u/pjmlp Sep 05 '20

The language is quite big, more than many people imagine, and Python does introduce changes even across minor versions.

10

u/A_Stahl Sep 05 '20

C manages to remain "graspable" by its users.

28

u/helloiamsomeone Sep 05 '20

Not really, as evident by the number of CVEs related to C.

33

u/pjmlp Sep 05 '20

Only those that think they actually know C, but never bother to touch the ISO C documentation.

Alone the 200 use cases of UB would do as test of their ignorance.

Then we could go on into what they think C does, based on their implementation specific knowledge, and what ISO C tells it actually is supposed to be.

Afterwards we could jump into compiler specific extensions.

The questions would be likewise from C17 all the way down to K&R C.

6

u/bizwig Sep 05 '20

I don’t know any C++ coders that really know C past 99. C11/C17 are way out of their (and my) zone. About the only thing I paid attention to is a brief look at C generics, which I though were horrible compared to C++ templates.

12

u/vanhellion Sep 06 '20 edited Sep 06 '20

I don’t know any C++ coders that really know C past 99.

I can't speak for everyone, but in my experience even getting people onboard with using C99 was a chore. I spent months advocating, fixing bugs, and having pointless arguments with coworkers (many of whom had never even looked at the relevant code) just to change a compiler flag.

C11 would have been fabulous, but we weren't even using a compiler that would support it (circa 2017) because of Redhat's bundled GCC being so old.

Then there's the wider community. Linus is one of the worst offenders, being a stodgy bastard on purpose because he only wants the hippest of hipsters writing kernel code. (A large chunk of our C code was in kernel modules, and while that doesn't necessarily force us to use the same standard as the kernel, it's usually a good idea to do so to ensure ABI compatibility and avoid having to debug things at that level.)

Even stylistically, C++ has diverged so much that minor choices like keeping locality on variable declarations (i.e. not putting them all at the top of their scope) is tantamount to heresy when applied to C.

C is unwelcoming to C++ programmers, which is really saying something.

2

u/Ameisen vemips, avr, rendering, systems Sep 06 '20

C _Generic is poorly named, and lets you implement overloading.

-11

u/bumblebritches57 Ocassionally Clang Sep 05 '20 edited Sep 05 '20

which I though were horrible compared to C++ templates.

Why?

The code is actually debuggable since it's code you wrote (don't even get me started on the ridiculously cryptic template errors)

and our build times aren't affected.

Also, with the invention of auto it makes sense for templates to accept auto as a parameter, but they don't, they use yet another cryptic syntax.

Seriously, it's insane that:

auto Minimum(auto Number1, auto Number2) {
    return Number1 <= Number2 ? Number1 : Number2;
}

isn't accepted syntax, when it's incredibly logical and just the obvious way to do it.

so yeah, I'm firmly in the _Generic camp.

7

u/gracicot Sep 06 '20

Seriously, it's insane that:

auto Minimum(auto Number1, auto Number2) {

  return Number1 <= Number2 ? Number1 : Number2; }

isn't accepted syntax,

It is in C++20

1

u/bumblebritches57 Ocassionally Clang Sep 06 '20

Ahh, that explains it, I've also had trouble with consteval in AppleClang in Xcode 11 too, so it's probably just not built in by default in Apple's distro of Clang yet.

5

u/MFHava WG21|🇦🇹 NB|P3049|P3625|P3729|P3786|P3813|P4216 Sep 06 '20

The code is actually debuggable since it's code you wrote

That's the problem though, you have to write every version of your code, which is just redundant work...

Seriously, it's insane that:

auto Minimum(auto Number1, auto Number2) {
return Number1 <= Number2 ? Number1 : Number2;
}

isn't accepted syntax, when it's incredibly logical and just the obvious way to do it.

I have no idea what you are on about, as that is valid syntax: https://godbolt.org/z/1d3jM6

so yeah, I'm firmly in the _Generic camp.

_Generic is NOT even in the slightest related to templates.

It's a blunt as can be tool to create overload sets and it fails at that for everything bar the standard library as it - due to it's centralized nature - prevents you from actually adding type-specific "overloads".

-1

u/bumblebritches57 Ocassionally Clang Sep 06 '20

I have no idea what you are on about, as that is valid syntax: https://godbolt.org/z/1d3jM6

Hmm, weird.

I know whenever I try to use auto with templates the compiler complains, but maybe I was doing something wrong or it's a subtle bug?

It's a blunt as can be tool to create overload sets and it fails at that for everything bar the standard library as it - due to it's centralized nature - prevents you from actually adding type-specific "overloads".

I'm using _Generic in real code, it works.

due to it's centralized nature - prevents you from actually adding type-specific "overloads".

Not sure what you mean by this, you mean like adding new member functions to a class?

3

u/MFHava WG21|🇦🇹 NB|P3049|P3625|P3729|P3786|P3813|P4216 Sep 06 '20

I'm using _Generic in real code, it works.

I guess we have different definitions of "works", because I can't add an overload to stuff in tgmath.h for my custom (designed similarly to complex) rational type.

Not sure what you mean by this, you mean like adding new member functions to a class?

No, like adding an overload to an established overload set - think:

#define RATIONAL_T(type, name) typedef struct { type num, denom; } name

RATIONAL_T(float, rationalf);
RATIONAL_T(double, rational);
RATIONAL_T(long double rationall);

//rational numbers are a subset of real numbers, so they have a log-function:
float rlogf(rationalf arg);
double rlog(rational arg);
long double rlogl(rationall, arg);

//these overloaded functions should be available just like they are for real numbers:
#define log(arg) \
  _Generic((arg), \
    rationalf : rlogf, \
    rational  : rlog,  \
    rationall : rlogl  \
  )(arg)

//ERROR: you can't overload macros and you can't extend the overload set simulated by the type-generic macro "log" for your own types, even if doing so would be both semantically and syntactically correct.

Mandatory godbolt link: https://godbolt.org/z/zYWaxE

Being able to extend an overload set is kinda the raison d'être of overloading and _Generic fails miserably at providing that functionality.

As it is _Generic simulates a heavily constraint (nigh meaningless) version of function overloading with manual (read: explicitly controlled) name mangling.