C++Now 2021 has ended
Back To Schedule
Friday, May 7 • 7:00am - 8:30am
Simplest Safe Integers

Log in to save this to your schedule, view media, leave feedback and see who's attending!

This talk will show some of the pitfalls and undefined behavior of C++'s C heritage with respect to built-in types and available operations. It will use the upcoming MISRA-C++ guidelines on that area to motivate and guide a simple integer library that allows easy conformance to what MISRA-C calls "essential type model" and that will be similarly represented in C++. Using that library of "integer" types, you will be able to write code that if it would be using regular integer types would be conforming with MISRA guidelines covering that area. While not "perfect" in the sense of safety it will provide types that do not promote, stick to their signedness and number of bits, wand wrap around. For example, adding an 200_ui8 + 56_ui8 will result in 1_ui8. The implementation will demonstrate the use of enum class types, operator overloading, user-defined literals.

Code is available at github.com/PeterSommerlad/PSsimplesafeint

avatar for Peter Sommerlad

Peter Sommerlad

founder, Better Software: Consulting, Training, Reviews
Peter Sommerlad was director of IFS Institute for Software at FHO/HSR Rapperswil, Switzerland. Peter is co-author of the books POSA Vol.1 and Security Patterns and contributed to "97 things every programmer should know". His goal is to make software simpler and safer by Decremental... Read More →

Friday May 7, 2021 7:00am - 8:30am MDT