News for hackers. Stuff that matters.
Re:Ziglings: Learn the Zig programming language by fixing ti... by fpoling on Saturday February 13, 2021 @06:21PM (#26128000)
The standard library of C++ assumes exceptions and that dictates code style that, even if one assumes infallible allocations and disable exceptions, one gets suboptimal code. So even with exceptions off one pays the price either in the form of non-standard library or accepting non-optimal performance. And if one has to prepare for fallible allocations, then the standard C++ is of no use at all in practice.
Re:Ziglings: Learn the Zig programming language by fixing ti... by pjmlp on Sunday February 14, 2021 @02:12AM (#26130336)
I assume you aren't that comfortable with ISO C++, the standard does allow for failible allocations.

That is the role nothrow in placement new, and custom STL allocators as language tool.

Additionally plenty of APIs now have exception and error based versions with noexcept.

Re:Ziglings: Learn the Zig programming language by fixing ti... by fpoling on Sunday February 14, 2021 @03:19AM (#26130558)
The fallible allocators require to use exceptions. There is no way to use, for example, C++ containers with fallible allocators and disabled exceptions.

But even with exceptions enabled fallible allocation in practice does not work. There was an article that made malloc to return null randomly. All tested C++ implementations crashed then because they allocated memory when generating exceptions.

Re:Ziglings: Learn the Zig programming language by fixing ti... by pjmlp on Sunday February 14, 2021 @03:38AM (#26130640)
Stop talking in circles and point out ISO C++20 sections then.

I am also curious to see how serious was that article.

Re:Ziglings: Learn the Zig programming language by fixing ti... by fpoling on Sunday February 14, 2021 @04:59AM (#26130974)
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2019/p070... - this discusses a lot of issues with exceptions as in ISO C++ and concrete proposals to make exceptions cost-free. The section 4.3.5 discusses specifically memory allocations.
Re:Ziglings: Learn the Zig programming language by fixing ti... by pjmlp on Sunday February 14, 2021 @09:00AM (#26132423)
Including parts that relate to Linux, have nothing to do with C++ and apply to any programming language.

You also skipped the section where Rust in its present state doesn't has any kind of recovery, it just panics.

Re:Ziglings: Learn the Zig programming language by fixing ti... by Quekid5 on Sunday February 14, 2021 @08:00AM (#26132054)
> So even with exceptions off one pays the price either in the form of non-standard library or accepting non-optimal performance.

Holy moving goalposts, batman!

The "don't pay..." thing has only ever applied to runtime, there nothing in there about not having to write more code yourself, etc.

(It's also a bit dubious in the first place. Chandler had a good talk about this at one of the CppCon's, IIRC. Can't be bothered to look it up, but it should be on YouTube.)