Live data from Hacker News

How to Adopt Modern C++17 into Your C++ Code [video]

youtube.com

41–50 of 124 posts

Re: How to Adopt Modern C++17 into Your C++ Code [video]

#41
post #39

Earlier quoted context omitted.

1. Do you see the bloat even if you don't use post C++11 features but compile using the C++17 standard? Yes, actually I tried using various C++ snippets and even reported that to the GCC compiler team. It happens with simple stuff like std::string and std::vector. The response was something like, that there really seems to be a bloat, but no performance impact and I guess most users outside of embedded don't care too…

Did you try with optimisations enabled? Here is a (trivial) program comparing gcc output between -std=c++14 and -std=c++17: https://godbolt.org/g/VLDhYf . Note that the output code size with -std=c++17 is significantly larger without optimisations (default), but it is identical with optimisations turned on!

I used -Os as for any embedded code where I don't care too much about the performance and rather need a compact binary.

I would love to post my code snippets from back then, but Im not home currently and the time Im back home I guess nobody will care about this anymore :D. Maybe I put it into an article.

Re: How to Adopt Modern C++17 into Your C++ Code [video]

#42

C++17 is definitely going in the right direction for most applications. But I have the feeling, that the compiler implementations cannot catch up with the modernization speed. We are using C++ for embedded devices and recognize a steady code bloat with every release since C++11 (especially with C++17) without using any of the new features (with gcc/clang). This is a trust-killer and actually the reason we stay on C++…

Just curious: why did you choose C++ instead of C for embedded? Most shops I know chose C just because of code bloat.

You can write modern C++ with no overhead on a system with just 16kB of scratchpad memory. It is much nicer to use than C (namespaces, auto, templates and lambdas alone).

Re: How to Adopt Modern C++17 into Your C++ Code [video]

#43
post #32

Earlier quoted context omitted.

I would be really interested if you can shed a little light on the following related questions: 1. Do you see the bloat even if you don't use post C++11 features but compile using the C++17 standard? 2. Do you think it is mostly the compiler that is causing the bloat alone? Or is it stuff from the standard library header files that some how gets linked in (and are not used or needed by your software)?

I haven't tried c++17 year, but c++98->c++11 did bring about code bloat. However even though we were building the same code base for two different systems, one without a C++11 compiler (thus we could not use c++11 features): it is incorrect to say we were not using C++11. Just turning on C++11 in the compiler brings move to all standard library containers. The header files were not just "somehow" linked in and not us…

What do you mean by code bloat?

Re: How to Adopt Modern C++17 into Your C++ Code [video]

#45
post #33

Sanity check, does gcc support all of these?

Yes, but the final version of the C++17 standard was released as late as December 2017, so support may not be "production ready", neither in gcc nor in other compilers. You can the summary of the gcc c++ standard support here: https://gcc.gnu.org/projects/cxx-status.html#cxx17 . Full support for all features in the c++17 standard, but the support is declared "experimental". Similarly here for clang: https://clang.llv…

Maybe I'm missing something, but http://en.cppreference.com/w/cpp/compiler_support seems to have it all in one place.

Re: How to Adopt Modern C++17 into Your C++ Code [video]

#46
post #44

I just checked how many times I use explicit delete in my moderately sized 7K LOC C++ project: just once. In code that interfaces with an old library. Modern C++ is not only practical. It's easy.

You using smart pointers from C++11 or later?

Re: How to Adopt Modern C++17 into Your C++ Code [video]

#48
post #39

Earlier quoted context omitted.

Did you try with optimisations enabled? Here is a (trivial) program comparing gcc output between -std=c++14 and -std=c++17: https://godbolt.org/g/VLDhYf . Note that the output code size with -std=c++17 is significantly larger without optimisations (default), but it is identical with optimisations turned on!

I used -Os as for any embedded code where I don't care too much about the performance and rather need a compact binary. I would love to post my code snippets from back then, but Im not home currently and the time Im back home I guess nobody will care about this anymore :D. Maybe I put it into an article.

If I had to guess, -Os prevents most inlining and in inlining is is pretty much required to remove most of the pure compile time abstraction and indirection that is used even on most trivial C++ libraries. Very likely libstdc++ make significant use of that.

The intermediate inline stages greatly expand the code size, until the point level where all the abstraction can be compiled away. I guess that -Os simply settles for a local optimum and gives up inlining early.

Re: How to Adopt Modern C++17 into Your C++ Code [video]

#49

Earlier quoted context omitted.

Just curious: why did you choose C++ instead of C for embedded? Most shops I know chose C just because of code bloat.

I have to admit, that C++ is still not the industry "Go-To" language for embedded. But if you apply modern C++ correctly, there is very few overhead compared to C and the software is much easier to maintain. The performance of embedded MCU's are continuously rising over the years and that little overhead is buying development speed. Not to mention smart pointers, templates and constexpr making my life easier. The onl…

When I was using C++ for embedded, which is admittedly over 15 years ago, I had to switch off RTTI and exception handling to get compact binaries. Basically just using classes and surface language features. We did use templates but only very selectively.

Is it still possible today to pare down the compiler output like that? I imagine a lot of modern C++ just doesn't work unless everything is enabled.

Re: How to Adopt Modern C++17 into Your C++ Code [video]

#50

Earlier quoted context omitted.

Just curious: why did you choose C++ instead of C for embedded? Most shops I know chose C just because of code bloat.

If there is a modern C++ compiler available for a platform, it is almost irresponsible to use straight C. That doesn't mean that everything needs to be pure idiomatic C++17, but destructors, templates, iteration, operator overloading and move semantics are still indispensable in non trivial programs. Avoiding bloat and performance hits are trivial in comparison to structural and architectural benefits in the modern l…

You're overstating a bit but there's a kernel of truth. However, it depends on your viewpoint. If you have a functional codebase in C and size is an important factor you may be reluctant to trade up. Bloat avoidance is not trivial, in my opinion. Performance is probably less of a factor, most of the additional functionality generated by the C++ compiler has to be written by the C coder in the end.
Post reply on HN