Live data from Hacker News

Overview: What are Cpp2 and cppfront? How do I get and build cppfront?

hsutter.github.io

131–140 of 174 posts

Re: Overview: What are Cpp2 and cppfront? How do I get and build cppfront?

#131

Earlier quoted context omitted.

There's barely a point in making a better C++ if you're not going to address one of the most obvious footguns.

The main iteration this cycle for the next C++ is contracts. Contracts are all about introducing undefined behaviour if you don't satisfy a precondition. In practice this improves software quality on many levels by clearly defining requirements on interface boundaries that would otherwise be implicit or just documented. Of course you can have special debug modes where you actually check that contracts are being satis…

> The main iteration this cycle for the next C++ is contracts.

As ever the C++ train leaves on schedule with or without anything you suppose is "promised" for that standard revision. This has been the practice since 2011 and I don't expect it to stop unless ISO tells them "Enough" or the whole thing comes apart.

> Contracts are all about introducing undefined behaviour if you don't satisfy a precondition.

Nope. That's explicitly not what the proposal sets out to do. It is likely that, as usual, WG21 will manage to take facilities intended to be safe, file them to a sharp edge and then slit their own throats, but P2900 in its current form doesn't do so. Here's an item from the proposal's list of things they're explicitly not proposing:

"The ability to assume that an unchecked contract predicate would evaluate to true, and allow the compiler to optimize based on that assumption, i.e. the assume semantic"

One of the three significant implementers, Microsoft, actually strongly objects to any idea of introducing yet more Undefined Behaviour into a language that is distinctly underwater when it comes to provable correctness. Microsoft shut down previous proposals in this area, and while they might (wrongly IMO) be sold the compromise position that's advocated by some WG21 members today (some UB in some contract checks), you're asking for a lot more.

Re: Overview: What are Cpp2 and cppfront? How do I get and build cppfront?

#132
post #127

Earlier quoted context omitted.

I kinda like it, it's comfortable and pragmatic. I don't have to look at the docs to figure out what's the format specifier for something like a size_t, and you can easily add support for whatever might be needed, so you can comfortably do: std::cout And get the x/y/z breakdown automatically.

But you can do that with fmtlib/std::format as well when you provide formatting for custom types, that just becomes: fmt::println("Player is at {}", _player_pos);

Should be possible to implement cout more effectively since there is no string parsing. I say “should” because in practice it seems to be the other way around. I don’t know why.

Re: Overview: What are Cpp2 and cppfront? How do I get and build cppfront?

#133
post #116

Earlier quoted context omitted.

I think the original point was to make a typesafe printf that's still reasonably efficient without creating a bunch of small temporary strings. Like, if you printf like this: printf("Number %d, String %s", n, s); but the types of n and s aren't int and char*, all hell breaks loose and you have the origin of a million CVEs. But how do you make that function signature typesafe, without the tools of modern templates? Yo…

It would have been possible to, as a special case, type check the formatting, C compilers began doing that in the 1990s IIRC.

And there are ways of signaling to a compiler that your function accepts a format string and a series of typed arguments in case you're wrapping a C-style printf function.

Re: Overview: What are Cpp2 and cppfront? How do I get and build cppfront?

#134

It's a nice idea, but not clear that it can truly interoperate with vanilla C++ libs which I think is required. Seems to be waiting for modules to be finalized, but whether cpp2 can call cpp, and cpp can call cpp2 without implementing half of a C++ compiler isn't obvious. https://github.com/hsutter/cppfront/issues/594

It's a just a transpiler to valid C++ code, so calling C++ code from cpp2 should be fine, but calling cpp2 code from C++ is an issue. There is no implementing half of a C++ compiler because it just uses clang or something after it is done transpiling.

Re: Overview: What are Cpp2 and cppfront? How do I get and build cppfront?

#135
post #116

Earlier quoted context omitted.

I think the original point was to make a typesafe printf that's still reasonably efficient without creating a bunch of small temporary strings. Like, if you printf like this: printf("Number %d, String %s", n, s); but the types of n and s aren't int and char*, all hell breaks loose and you have the origin of a million CVEs. But how do you make that function signature typesafe, without the tools of modern templates? Yo…

It would have been possible to, as a special case, type check the formatting, C compilers began doing that in the 1990s IIRC.

It wouldn’t have added support for custom types to printf(), which was an important motivation.

Re: Overview: What are Cpp2 and cppfront? How do I get and build cppfront?

#136
post #22

> Because ++ and -- always have in-place update semantics, we never need to remember "use prefix ++/-- unless you need a copy of the old value." If you do need a copy of the old value, just take the copy before calling ++/-- I actually wish ++ and -- operators were removed. This would simplify everything, nothing to remember whether it's prefix or postfix operator, whether it copies something or not, you would just d…

Unfortunately, C++ uses ++ and -- for iterators, many of which cannot reasonably implement += or -=. This distinction is baked into the type system to tell whether or not an iterator supports efficient "multiple advance" (e.g. a linked list iterator doesn't have += but a pointer into a contiguous vector does). There's no way to fix this in a reverse-compatible way for existing code (which is one of the constraints of…

A noncopying ++ could be spelled `+= 1` though. So some iterators would support `+= 1`, but not `+= 2`. This would be vaguely similar to how the null pointer constant was defined as an integer constant expression that evaluates to zero: Define `+= integer constant expression that evaluates to one>` as the increment operator.

Re: Overview: What are Cpp2 and cppfront? How do I get and build cppfront?

#137
post #22

> Because ++ and -- always have in-place update semantics, we never need to remember "use prefix ++/-- unless you need a copy of the old value." If you do need a copy of the old value, just take the copy before calling ++/-- I actually wish ++ and -- operators were removed. This would simplify everything, nothing to remember whether it's prefix or postfix operator, whether it copies something or not, you would just d…

But you would break the name! C++ would be a syntax error! I mean, there are people that already think that...

But it’s C++2, and that would become valid! (C + +2)

Re: Overview: What are Cpp2 and cppfront? How do I get and build cppfront?

#138
post #98

Earlier quoted context omitted.

> Anyway I have no idea if cpp2 would get support from microsoft or other devs, but cpp2 seems like the most humble and "least risky" solution for the future of C++, and I really want it to be. That ship has sailed. They already have C#.

C# is so old by now, if it would be a good replacement for C++ at MS, it would already have replaced it.

[deleted]

Re: Overview: What are Cpp2 and cppfront? How do I get and build cppfront?

#140
post #98

Earlier quoted context omitted.

> Anyway I have no idea if cpp2 would get support from microsoft or other devs, but cpp2 seems like the most humble and "least risky" solution for the future of C++, and I really want it to be. That ship has sailed. They already have C#.

C# is so old by now, if it would be a good replacement for C++ at MS, it would already have replaced it.

Don't mix technology with the internal politics at Microsoft, where some business units won't use anything else besides COM and C++, no matter what.

They are so strong that they were responsible pushing the whole company into the whole Windows 8 debacle with WinRT, where COM was supposed to finally replace .NET.

https://arstechnica.com/features/2012/10/windows-8-and-winrt...

Post reply on HN