should i adopt modern c++? · bertil spolander, senior software engineer. agenda •languages in...
TRANSCRIPT
![Page 1: Should I Adopt Modern C++? · Bertil Spolander, Senior Software Engineer. Agenda •Languages in Embedded Systems •Requirements on your software project •Advantages of C++ •Preconceptions](https://reader036.vdocuments.us/reader036/viewer/2022081404/5f0641f57e708231d4171656/html5/thumbnails/1.jpg)
Should I Adopt Modern C++?
Bertil Spolander, Senior Software Engineer
![Page 2: Should I Adopt Modern C++? · Bertil Spolander, Senior Software Engineer. Agenda •Languages in Embedded Systems •Requirements on your software project •Advantages of C++ •Preconceptions](https://reader036.vdocuments.us/reader036/viewer/2022081404/5f0641f57e708231d4171656/html5/thumbnails/2.jpg)
Agenda
• Languages in Embedded Systems
• Requirements on your software project
• Advantages of C++
• Preconceptions of C++
• Modern C++
• Take care
• Summary
![Page 3: Should I Adopt Modern C++? · Bertil Spolander, Senior Software Engineer. Agenda •Languages in Embedded Systems •Requirements on your software project •Advantages of C++ •Preconceptions](https://reader036.vdocuments.us/reader036/viewer/2022081404/5f0641f57e708231d4171656/html5/thumbnails/3.jpg)
Languages in Embedded Systems
![Page 4: Should I Adopt Modern C++? · Bertil Spolander, Senior Software Engineer. Agenda •Languages in Embedded Systems •Requirements on your software project •Advantages of C++ •Preconceptions](https://reader036.vdocuments.us/reader036/viewer/2022081404/5f0641f57e708231d4171656/html5/thumbnails/4.jpg)
What languages are used in Embedded
Systems today?
![Page 5: Should I Adopt Modern C++? · Bertil Spolander, Senior Software Engineer. Agenda •Languages in Embedded Systems •Requirements on your software project •Advantages of C++ •Preconceptions](https://reader036.vdocuments.us/reader036/viewer/2022081404/5f0641f57e708231d4171656/html5/thumbnails/5.jpg)
Requirements on your
software project
![Page 6: Should I Adopt Modern C++? · Bertil Spolander, Senior Software Engineer. Agenda •Languages in Embedded Systems •Requirements on your software project •Advantages of C++ •Preconceptions](https://reader036.vdocuments.us/reader036/viewer/2022081404/5f0641f57e708231d4171656/html5/thumbnails/6.jpg)
What’s important
• Small code footprint
– Saves flash and thus money
• Fast execution
– Keep up with peripherals
– Better user experience
![Page 7: Should I Adopt Modern C++? · Bertil Spolander, Senior Software Engineer. Agenda •Languages in Embedded Systems •Requirements on your software project •Advantages of C++ •Preconceptions](https://reader036.vdocuments.us/reader036/viewer/2022081404/5f0641f57e708231d4171656/html5/thumbnails/7.jpg)
What’s important (cont.)
• Have a good design
– Easier to maintain
– Easier to extend functionality
• High quality
• Time to market
– Earlier return on investment
![Page 8: Should I Adopt Modern C++? · Bertil Spolander, Senior Software Engineer. Agenda •Languages in Embedded Systems •Requirements on your software project •Advantages of C++ •Preconceptions](https://reader036.vdocuments.us/reader036/viewer/2022081404/5f0641f57e708231d4171656/html5/thumbnails/8.jpg)
Advantages of C++
![Page 9: Should I Adopt Modern C++? · Bertil Spolander, Senior Software Engineer. Agenda •Languages in Embedded Systems •Requirements on your software project •Advantages of C++ •Preconceptions](https://reader036.vdocuments.us/reader036/viewer/2022081404/5f0641f57e708231d4171656/html5/thumbnails/9.jpg)
Why C++ instead of C
• Better modularity, which comes from the ability to couple data with the
methods and operators that manipulate it.
• Reuse of code by inheritance. You can have existing code that you can
use while still be able to specialize and enhance it.
• Flexibility through polymorphism. Being able to use the same interface
to different types of objects makes it easier to maintain stable API’s.
• Higher levels of abstraction where you can hide the implementation to a
higher degree.
• Larger standard library which means less programming for you with
better tested code.
![Page 10: Should I Adopt Modern C++? · Bertil Spolander, Senior Software Engineer. Agenda •Languages in Embedded Systems •Requirements on your software project •Advantages of C++ •Preconceptions](https://reader036.vdocuments.us/reader036/viewer/2022081404/5f0641f57e708231d4171656/html5/thumbnails/10.jpg)
Preconceptions of C++
![Page 11: Should I Adopt Modern C++? · Bertil Spolander, Senior Software Engineer. Agenda •Languages in Embedded Systems •Requirements on your software project •Advantages of C++ •Preconceptions](https://reader036.vdocuments.us/reader036/viewer/2022081404/5f0641f57e708231d4171656/html5/thumbnails/11.jpg)
Preconceptions of C++
• Bloated
– Code size
– Data size
• Inefficient
– Pure performance and reliability of the performan
– Uses the heap to much
• Hard to debug
![Page 12: Should I Adopt Modern C++? · Bertil Spolander, Senior Software Engineer. Agenda •Languages in Embedded Systems •Requirements on your software project •Advantages of C++ •Preconceptions](https://reader036.vdocuments.us/reader036/viewer/2022081404/5f0641f57e708231d4171656/html5/thumbnails/12.jpg)
Modern C++
![Page 13: Should I Adopt Modern C++? · Bertil Spolander, Senior Software Engineer. Agenda •Languages in Embedded Systems •Requirements on your software project •Advantages of C++ •Preconceptions](https://reader036.vdocuments.us/reader036/viewer/2022081404/5f0641f57e708231d4171656/html5/thumbnails/13.jpg)
History
• C++ and Embedded Systems mid 1990’s
– Bloated, slow, hard to debug
• Standards 1998 and 2003, not much happened
• C++ 2011
– Major changes and additions to the language
– Continued with C++ 14 and C++ 17
• Modern C++ starts with C++ 2011
![Page 14: Should I Adopt Modern C++? · Bertil Spolander, Senior Software Engineer. Agenda •Languages in Embedded Systems •Requirements on your software project •Advantages of C++ •Preconceptions](https://reader036.vdocuments.us/reader036/viewer/2022081404/5f0641f57e708231d4171656/html5/thumbnails/14.jpg)
Modern C++, features
• Efficiency
– Move semantics
– Constant expressions
• Conveniance
– Range based for-loops
– Automatic type inference
– Attributes
![Page 15: Should I Adopt Modern C++? · Bertil Spolander, Senior Software Engineer. Agenda •Languages in Embedded Systems •Requirements on your software project •Advantages of C++ •Preconceptions](https://reader036.vdocuments.us/reader036/viewer/2022081404/5f0641f57e708231d4171656/html5/thumbnails/15.jpg)
Temporary objects
![Page 16: Should I Adopt Modern C++? · Bertil Spolander, Senior Software Engineer. Agenda •Languages in Embedded Systems •Requirements on your software project •Advantages of C++ •Preconceptions](https://reader036.vdocuments.us/reader036/viewer/2022081404/5f0641f57e708231d4171656/html5/thumbnails/16.jpg)
Move semantics
![Page 17: Should I Adopt Modern C++? · Bertil Spolander, Senior Software Engineer. Agenda •Languages in Embedded Systems •Requirements on your software project •Advantages of C++ •Preconceptions](https://reader036.vdocuments.us/reader036/viewer/2022081404/5f0641f57e708231d4171656/html5/thumbnails/17.jpg)
Constant expressions
constexpr int function(...)
• Enables the use of functions where you
can only use constants.
• Requires that the compiler can calculate
the value of the function at compile time.
![Page 18: Should I Adopt Modern C++? · Bertil Spolander, Senior Software Engineer. Agenda •Languages in Embedded Systems •Requirements on your software project •Advantages of C++ •Preconceptions](https://reader036.vdocuments.us/reader036/viewer/2022081404/5f0641f57e708231d4171656/html5/thumbnails/18.jpg)
Automatic type inference
• I want the type of that expressionstd::vector<int> myvector;
for (std::vector<int>::iterator it = myvector.begin() ; it != myvector.end(); ++it)
{
std::cout << ' ' << *it;
}
std::vector<int> myvector;
for (auto it = myvector.begin() ; it != myvector.end(); ++it)
{
std::cout << ' ' << *it;
}
auto yourfunction(int i)
{
int local;
...
return local;
![Page 19: Should I Adopt Modern C++? · Bertil Spolander, Senior Software Engineer. Agenda •Languages in Embedded Systems •Requirements on your software project •Advantages of C++ •Preconceptions](https://reader036.vdocuments.us/reader036/viewer/2022081404/5f0641f57e708231d4171656/html5/thumbnails/19.jpg)
Attributes
[[noreturn]] - This function will not return
[[deprecated]] - This symbol is deprecated
[[override]] - This function intends to override a function
[[final]] - This is should not be overridden
[[fallthrough]] - This is intentional, don’t emit a warning
![Page 20: Should I Adopt Modern C++? · Bertil Spolander, Senior Software Engineer. Agenda •Languages in Embedded Systems •Requirements on your software project •Advantages of C++ •Preconceptions](https://reader036.vdocuments.us/reader036/viewer/2022081404/5f0641f57e708231d4171656/html5/thumbnails/20.jpg)
Demonstration, debug support
![Page 21: Should I Adopt Modern C++? · Bertil Spolander, Senior Software Engineer. Agenda •Languages in Embedded Systems •Requirements on your software project •Advantages of C++ •Preconceptions](https://reader036.vdocuments.us/reader036/viewer/2022081404/5f0641f57e708231d4171656/html5/thumbnails/21.jpg)
Use with care
![Page 22: Should I Adopt Modern C++? · Bertil Spolander, Senior Software Engineer. Agenda •Languages in Embedded Systems •Requirements on your software project •Advantages of C++ •Preconceptions](https://reader036.vdocuments.us/reader036/viewer/2022081404/5f0641f57e708231d4171656/html5/thumbnails/22.jpg)
Careful…
• Run time type information (RTTI)
• Exceptions
• Standard library
– Particularly STL
![Page 23: Should I Adopt Modern C++? · Bertil Spolander, Senior Software Engineer. Agenda •Languages in Embedded Systems •Requirements on your software project •Advantages of C++ •Preconceptions](https://reader036.vdocuments.us/reader036/viewer/2022081404/5f0641f57e708231d4171656/html5/thumbnails/23.jpg)
Summary
![Page 24: Should I Adopt Modern C++? · Bertil Spolander, Senior Software Engineer. Agenda •Languages in Embedded Systems •Requirements on your software project •Advantages of C++ •Preconceptions](https://reader036.vdocuments.us/reader036/viewer/2022081404/5f0641f57e708231d4171656/html5/thumbnails/24.jpg)
Summary
• C++ is better than C for creating and maintaining high quality software.
• Modern C++ and modern tools make the old preconceptions not so prevalent anymore.
• Choose carefully what features you use to limit loss in performance
![Page 25: Should I Adopt Modern C++? · Bertil Spolander, Senior Software Engineer. Agenda •Languages in Embedded Systems •Requirements on your software project •Advantages of C++ •Preconceptions](https://reader036.vdocuments.us/reader036/viewer/2022081404/5f0641f57e708231d4171656/html5/thumbnails/25.jpg)
Thank you for your attention!
www.iar.com