6 ms·
What is C++ tradition? Is it that one does not pay for a feature unless one uses it? In practice C++ broke with that with exceptions and RTTI. Even Rust does ad
by fpoling 6y ago
What is C++ tradition? Is it that one does not pay for a feature unless one uses it? In practice C++ broke with that with exceptions and RTTI. Even Rust does adhere to it since its standard library assumes infallible allocations making one to pay for not relying on it in the form of having to write an alternative library.
- pjmlp 6y agoThat would be the case if one wasn't allowed to turn them off.
- fpoling 6y agoThe 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.
- pjmlp 6y agoI 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.
- fpoling 6y agoThe 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.
- pjmlp 6y agoStop talking in circles and point out ISO C++20 sections then. I am also curious to see how serious was that article.
- fpoling 6y agohttp://www.open-std.org/jtc1/sc22/wg21/docs/papers/2019/p0709r3.pdf 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.
- pjmlp 6y agoIncluding 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.
- Quekid5 6y ago> 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.)
- pron 6y agoIn all low-level languages you don't pay for what you don't use; that's not a design tradition but a requirement of the domain. I'm talking about the tradition of a low-abstraction, low-level language that has many features so that, when it is read on the page it appears as if it were high-level.