Earlier quoted context omitted.
No, C has much less RVO allowed than C++. I provided an example of this here the last time : https://news.ycombinator.com/item?id=17216250
From what I can see, the example you list there is just a missed optimization in the C compilers you tested. It's absolutely allowed, and clang trunk is happy to do it in C-mode, for example.
Modern C++ for C Programmers: part 5
31–40 of 82 posts
Re: Modern C++ for C Programmers: part 5
#32Re: Modern C++ for C Programmers: part 5
#33Please please please can we get rid of headers and have modules? I find it super annoying having to specify things half in one place and half in another. Unfortunately, there still seems to be a bit of disagreement on the implementation among the standards committee.
Absolutely There keeps being proposals for C++ standard modules, and it keeps getting punted. Having a reasonable module system, and hell even some lovely tools for migrating sane projects over to it, would make me much happier with the language. For what it's worth, Clang has experimental support for C++ modules.
The trouble being actually indexing the contents of any given module and trouble with template instantiation.
Re: Modern C++ for C Programmers: part 5
#34is there a modern C++ for python programmers? i have ~5 years programming in dynamic/interpreted (python/js) and compiled/gc'd(java/go) languages and i'd like to learn a systems language. i'm reading the rust programming book (and it's really good/easy to grok) but i'd also like to learn C++. the problem is that most books are either too easy (C++ as your first language) or too hard (straight into RAII and templates)…
I wouldn't get too hung up on skipping straight to "modern" C++. Yes, C++11 is a game changer, but the vast majority of what you'll find in the classic recommendations is still worth knowing. Things like type deduction, smart pointers, and move semantics won't be hard to pick up once you've got the basics. Although I haven't read it, Accelerated C++ sounds like a good fit for your situation.
Re: Modern C++ for C Programmers: part 5
#35Earlier quoted context omitted.
What's the motivation behind this?
The committee probably observed that in most cases where people wanted a move constructor, they needed either no copy constructor or a more complicated one (to handle duplicating a resource.) So creating a default copy constructor (a convenience in the common case of a simple structure) wasn't a win. Perhaps if you were designing C++ from scratch without legacy and had a more Python-like mindset, you'd require an exp…
Re: Modern C++ for C Programmers: part 5
#36Please please please can we get rid of headers and have modules? I find it super annoying having to specify things half in one place and half in another. Unfortunately, there still seems to be a bit of disagreement on the implementation among the standards committee.
What a header actually does depends on compiler flags, #defines from other files and then the order in which you include things as one header file might define something that changes the behavior of another header file. The compiler loses state in between C++-files and caching precompiled header files was still a joke the last time I've checked.
That leads to the problem that every single C++ file needs to include a few hundred thousand lines of nested headers and compilation takes forever. Add in some templates and you get a lot duplicated code in the object files that needs to be weeded out by the linker. Sometimes it's even suggested to put all your classes into one single big C++ file and only compile that in order to get your compilation time down.
Having proper modules would do so much good!
Re: Modern C++ for C Programmers: part 5
#37I wish I had a project that warranted C++ right now. It’s a magnificent language.
I've had a blast with OOP in C++, believe it or not, and writing my recursive descent parser, symbol table, and analyzer felt like working with a higher-level language.
Re: Modern C++ for C Programmers: part 5
#38is there a modern C++ for python programmers? i have ~5 years programming in dynamic/interpreted (python/js) and compiled/gc'd(java/go) languages and i'd like to learn a systems language. i'm reading the rust programming book (and it's really good/easy to grok) but i'd also like to learn C++. the problem is that most books are either too easy (C++ as your first language) or too hard (straight into RAII and templates)…
"If you really want to learn C++, I advise against any and all online tutorials and against most books. Without any kind of quality control, many professional book writers published many awful C++ textbooks that may be easy to read and sell well, but teach lies. Stick with the community-verified book list available at StackOverflow"
In other words, use the StackOverflow list to choose the right teaching material [2]. A Tour of C++ (Bjarne Stroustrup) has been a good refresher, with C++ Primer (Stanley Lippman, Josée Lajoie, and Barbara E. Moo) as the primary reference for further clarification. Also use GeeksForGeeks and LeetCode practice problems.
[1] https://www.quora.com/Which-is-the-best-book-for-learning-c+... [2] https://stackoverflow.com/questions/388242/the-definitive-c-...
Re: Modern C++ for C Programmers: part 5
#39Earlier quoted context omitted.
Performance critical.
Also if Rust is not cutting it yet in your specific niche.
Re: Modern C++ for C Programmers: part 5
#40Please please please can we get rid of headers and have modules? I find it super annoying having to specify things half in one place and half in another. Unfortunately, there still seems to be a bit of disagreement on the implementation among the standards committee.
Includes mixed with #ifdef leaks state across module borders and the whole C preprocessor feels like a dirty hack. What a header actually does depends on compiler flags, #defines from other files and then the order in which you include things as one header file might define something that changes the behavior of another header file. The compiler loses state in between C++-files and caching precompiled header files wa…
Going away from C's linker and header file-model, which really doesn't work well for C++, to something based on a proper module system, would be amazing.