Sign up for the KDAB Newsletter
Stay on top of the latest news, publications, events and more.
Go to Sign-up


Find what you need - explore our website and developer resources
3 May 2021
Since almost all embedded devices interact with the physical world, the reoccurring problem is how to deal with the various values from the physical world. One sensor may measure the current in milliamperes, while another may measure it in microamperes. There are also different measurement systems, such as metric and imperial (e.g. gallons and litres, metres and yards, etc.), but there are also units that overlap with others (e.g. litres and metres cubed, Kelvin and Celsius). Even worse, we must ensure that all arithmetic operations with physical values must be valid (e.g. we can’t add Volts and Kelvins, but we can multiply them). Thankfully, modern C++ offers a lot of built-in language functionalities to make this job easy, transparent and surprisingly optimal in the run time.
This work was motivated by a past project in which many subtle bugs were caused by inconsistent treatment of measured values.
You will learn:
– how we can use SI system of units for our benefit
– the typical requirements and constraints on the real embedded projects concerning the physical units
– which features from modern C++ are useful for this job
– the difference between absolute and relative values
– how to write your own implementation
– how to make the refactored code readable and succinct
0:00 Introduction
1:04 Beginning of Talk
37:02 Q&A Session
The slides of the talk can be found here https://www.qtembeddeddays.com/dealing-with-physical-units-in-modern-c/
About the speaker
Nikola Jelić, Embedded Software Architect in Zuehlke from 2016.
Nikola graduated in Computer Science at Faculty of Mathematics in Belgrade, Serbia. He has 11+ years of embedded development experience focused mostly on Linux, C++ and real-time systems. Nikola prefers functional paradigm to all others, but is pragmatic about it.
Stay on top of the latest news, publications, events and more.
Go to Sign-up
Learn Modern C++
Our hands-on Modern C++ training courses are designed to quickly familiarize newcomers with the language. They also update professional C++ developers on the latest changes in the language and standard library introduced in recent C++ editions.
Learn more