SlideShare a Scribd company logo
1 of 23
Exiting the Dark Ages of Void* with C++11
*YOU* are full of bullshit.
C++ is a horrible language. It's made more horrible by the fact that a
lot of substandard programmers use it, to the point where it's much
much easier to generate total and utter crap with it. Quite frankly,
even if the choice of C were to do *nothing* but keep the C++
programmers out, that in itself would be a huge reason to use C.
-Linus Torvalds (2007)
http://harmful.cat-v.org/software/c++/linus
What is an embedded system?
Well, a lot of different things, but generally speaking:
● Dedicated to a single purpose
● Minimalist approach to reduce cost
● “Always on”
● Has stiff reliability requirements
● uses safeguards like watchdogs for recovery
Software selection based on
hardware?
Bare metal:
ATtiny85, 8K of flash
512 byte of SRAM
512 bytes of EEPROM
general-
purpose OS
(hopefully
ruggedized)
● Bare metal or
microkernel / RTOS
● Lots of C!
(ok, NASA uses some ADA)
Myths about C++ in embedded systems
● C++ code is slow compared to C
● C++ produces binaries too big for embedded systems
● Templates create too much code “bloat”
● Dynamic dispatch is slow. Virtual functions are too “heavyweight”.
● C++ is synonymous with dynamic allocation
● It’s too hard to port C++ to other architectures
● STL is the devil for embedded systems, therefore you shouldn’t use C++
Myth #1: C++ is slow
Truth: If you use C++ as
“C with classes” you will
get virtually indistinguishable
performance. Other lightweight
features add minimal overhead.
Certain features of C++ can be too slow or otherwise
unsuitable for certain embedded applications.
Myth #2: C++ Binaries Are Too Big
Truth:
Using a reasonable subset of features leads to similar
binary files sizes.
Frequently, higher level abstractions can reduce
copy/paste coding.
libstdc++ is big. It’s also frequently not available!
Myth #3: Templates create too much code bloat
Truth:
If you factor template independent code outside of your
templates, you can minimize this effect. Every good C++
programmer knows this.
Extensive use of macros in C produce bloat just as easily,
with more obfuscation, and with less type safety.
Myth #4: Dynamic Dispatch is “Slow”
Truth: The overhead from virtual functions &
vtables is actually pretty acceptable for almost
all applications.
● one vtable per class (not per object)
● one pointer to the vtable per object
● one dereferencing operation per call (a couple cycles on most hardware)
Virtual functions can be abused like any language feature. However, abstraction via
interfaces (abstract classes in C++) is too powerful a tool for building APIs and testing code
to ignore.
Lulz
http://freshbsd.org/commit/openbsd/8a6680833c42bde7de74b9ddb70bbad193c5359b
“Why do we hide from the
OpenSSL police, dad?”
“Because they're not like us,
son. They use macros to wrap
stdio routines, for an
undocumented
(OPENSSL_USE_APPLINK) use
case, which only serves to
obfuscate the code.”
Myth #5: C++ == dynamic allocation
Truth:
There is nothing about C++
that forces you to use dynamic
allocation.
If you don’t like the STL, don’t
use it. The STL is a library not
the language.
Myth #6: C++ leads to non-portable code
Truth:
This used to be true. C++ compilers have made
enormous strides in recent years for a number of
reasons. Clang and GCC are now driving progress, and
even MSVC++ is quite compliant to the standard.
If you develop with multiple compilers frequently and
avoid platform extensions, you’ll have excellent
portability. C++ abstractions make it easier to separate
platform-specific code.
Lulz
“I'm glad to know that Ultrix CC
has a bug optimizing switch()
statements lacking an explicit
`case 0:' construct. But Ultrix has
been dead for more than 15 years,
really. Don't give it any reason to
move out of its coffin.”
http://freshbsd.org/commit/openbsd/111423c9d25cd2128223242f0a3d7dcaa9acb3b5
Why is C++ “better now”?
● Renewed interest in native languages
● Clang (C-family front-end compiler for LLVM) has been pushing GCC to
improve
● Coopetition between Intel/Microsoft/OSS tools to be “conformant”
● Many embedded vendors have switched from proprietary toolchains to
GCC-based tools (expect even more to switch to Clang/LLVM)
What is Clang/LLVM?
LLVM is a language-agnostic compiler architecture. It separates language-
specific lexing / early-stage compilation from the translation & optimization of
specific targets.
Interested in creating a new language? No problem, it will easily be able to
target different architectures if your compile to LLVM.
Interested in adding support for a new architecture? Great, you only have to
translate LLVM instructions to your target.
“Lightweight” C++ for MCUs (MISRA?)
Free (no significant overhead vs. C)
● Classes
● Constructors / destructors & OOP modularity
● Single inheritance
● C++11 lambdas, constexpr, access modifiers
● templates (if factored appropriately)
Cheap:
● Virtual methods
Costly to some metric (performance / determinism / code size / runtime / memory / etc)
● dynamic allocation
● Virtual inheritance
● Run-time type information (RTTI == dynamic_cast<> & typeid)
● Exceptions
How can C++ improve robustness/security?
● More powerful abstractions
o private members - data hiding / encapsulation
o const correctness - enforce immutability
o deterministic destructors - guaranteed resource release
● Wrappers to that mediate access to dangerous resources
o e.g. buffer views (wrappers)
● Better type-safety means that you make fewer assumptions in code.
● Powerful design patterns can be applied to encourage better practices
Simple pattern, big effect: RAII
The Problem (pseudo code in C)
int stupidprefix_some_function_that_returns_error_code(.... arguments)
{
int err = 0;
stupidprefix_acquire_resource(&resource);
stupidprefix_do_stuff_with_resource(&resource);
// … yada yada lots of code branches that require resource
// from which you can’t return (hint: use GOTO)
CLEANUP:
stupidprefix_release_resource(&resource);
return err;
}
C++ version w/ RAII
namespace kickasswehavenamespaces
{
int some_function_that_returns_error_code(.... arguments)
{
Acquisition mediator(raw_resource);
do_stuff_with_resource(mediator);
//... Code branches
//... Any return calls mediator’s destructor
return 0;
}
}
The act of acquiring a resource
guarantees its release.
“Resource Acquisition Is
Initialization”.
Java doesn’t even have an
acceptable substitute.
C# has “using” statement.
“embeddable” C++11 features
● static_assert - Compile time assertions complete with custom compiler
error messages. Ensure that your library is being configured with safe
constants / types.
● constexpr - Compile time calculations (yet another Turing complete
metaprogramming language)
● Access modifiers for method (override final)
What specific design aims guided
the committee?
“Improve performance and ability to
work directly with hardware -- make
C++ even better for embedded
systems programming and high-
performance computation.”
http://www.stroustrup.com/C++11FAQ.html
So, dnp3 on Atmega2560?
CPU: 8-bit AVR
Max. Operating Freq. (MHz): 16 MHz
SRAM: 8K
Flash (Kbytes): 256 Kbytes
https://github.com/automatak/dnp3/blob/2.0.x/embedded/atmelavr/demooutstation
/main.cpp
AVR DNP3 Demo
● C++11 using GCC 4.8.1 and 8-bit AVR backend
● USART only at this point
● Level 3 stack - more feature-rich than many RTUs / IEDs
● All statically allocated
● All interrupt based event-loop
● Makes use of AVR sleep mode
● SAv5? maybe possible? Definitely on ARM Cortex (Arduino DUE)
● Community members have been prototyping on TI ARM & PIC
● Need an interesting I/O shield to make a real “IED”

More Related Content

What's hot

Native development kit (ndk) introduction
Native development kit (ndk)  introductionNative development kit (ndk)  introduction
Native development kit (ndk) introductionRakesh Jha
 
Presentation1
Presentation1Presentation1
Presentation1kpkcsc
 
Engineer Engineering Software
Engineer Engineering SoftwareEngineer Engineering Software
Engineer Engineering SoftwareYung-Yu Chen
 
Mbuf oflow - Finding vulnerabilities in iOS/macOS networking code - kevin ba...
 Mbuf oflow - Finding vulnerabilities in iOS/macOS networking code - kevin ba... Mbuf oflow - Finding vulnerabilities in iOS/macOS networking code - kevin ba...
Mbuf oflow - Finding vulnerabilities in iOS/macOS networking code - kevin ba...Semmle
 
Android Native Development Kit
Android Native Development KitAndroid Native Development Kit
Android Native Development KitPeter R. Egli
 
Android Developer Meetup
Android Developer MeetupAndroid Developer Meetup
Android Developer MeetupMedialets
 
Introduction to llvm
Introduction to llvmIntroduction to llvm
Introduction to llvmTao He
 
NDK Programming in Android
NDK Programming in AndroidNDK Programming in Android
NDK Programming in AndroidArvind Devaraj
 
GPCE16 Poster: Automatic Non-functional Testing of Code Generators Families
GPCE16 Poster: Automatic Non-functional Testing of Code Generators Families GPCE16 Poster: Automatic Non-functional Testing of Code Generators Families
GPCE16 Poster: Automatic Non-functional Testing of Code Generators Families Mohamed BOUSSAA
 
Python for IoT, A return of experience
Python for IoT, A return of experiencePython for IoT, A return of experience
Python for IoT, A return of experienceAlexandre Abadie
 
برنامه نویسی مستقل از پلتفرم با استفاده از .NET Core و C#
برنامه نویسی مستقل از پلتفرم با استفاده از .NET Core و C#برنامه نویسی مستقل از پلتفرم با استفاده از .NET Core و C#
برنامه نویسی مستقل از پلتفرم با استفاده از .NET Core و C#Shiraz LUG
 
Introduction to the Android NDK
Introduction to the Android NDKIntroduction to the Android NDK
Introduction to the Android NDKBeMyApp
 
Dotnet framework
Dotnet frameworkDotnet framework
Dotnet frameworkNitu Pandey
 
"Making OpenCV Code Run Fast," a Presentation from Intel
"Making OpenCV Code Run Fast," a Presentation from Intel"Making OpenCV Code Run Fast," a Presentation from Intel
"Making OpenCV Code Run Fast," a Presentation from IntelEdge AI and Vision Alliance
 
Dennis Benkert & Matthias Lübken - Patterns in a containerized world? - code....
Dennis Benkert & Matthias Lübken - Patterns in a containerized world? - code....Dennis Benkert & Matthias Lübken - Patterns in a containerized world? - code....
Dennis Benkert & Matthias Lübken - Patterns in a containerized world? - code....AboutYouGmbH
 
Using the android ndk - DroidCon Paris 2014
Using the android ndk - DroidCon Paris 2014Using the android ndk - DroidCon Paris 2014
Using the android ndk - DroidCon Paris 2014Paris Android User Group
 

What's hot (20)

Native development kit (ndk) introduction
Native development kit (ndk)  introductionNative development kit (ndk)  introduction
Native development kit (ndk) introduction
 
Presentation1
Presentation1Presentation1
Presentation1
 
Engineer Engineering Software
Engineer Engineering SoftwareEngineer Engineering Software
Engineer Engineering Software
 
Mbuf oflow - Finding vulnerabilities in iOS/macOS networking code - kevin ba...
 Mbuf oflow - Finding vulnerabilities in iOS/macOS networking code - kevin ba... Mbuf oflow - Finding vulnerabilities in iOS/macOS networking code - kevin ba...
Mbuf oflow - Finding vulnerabilities in iOS/macOS networking code - kevin ba...
 
Android Native Development Kit
Android Native Development KitAndroid Native Development Kit
Android Native Development Kit
 
Android NDK
Android NDKAndroid NDK
Android NDK
 
Net framework
Net frameworkNet framework
Net framework
 
Android Developer Meetup
Android Developer MeetupAndroid Developer Meetup
Android Developer Meetup
 
Introduction to llvm
Introduction to llvmIntroduction to llvm
Introduction to llvm
 
NDK Programming in Android
NDK Programming in AndroidNDK Programming in Android
NDK Programming in Android
 
GPCE16 Poster: Automatic Non-functional Testing of Code Generators Families
GPCE16 Poster: Automatic Non-functional Testing of Code Generators Families GPCE16 Poster: Automatic Non-functional Testing of Code Generators Families
GPCE16 Poster: Automatic Non-functional Testing of Code Generators Families
 
NDK Introduction
NDK IntroductionNDK Introduction
NDK Introduction
 
Python for IoT, A return of experience
Python for IoT, A return of experiencePython for IoT, A return of experience
Python for IoT, A return of experience
 
برنامه نویسی مستقل از پلتفرم با استفاده از .NET Core و C#
برنامه نویسی مستقل از پلتفرم با استفاده از .NET Core و C#برنامه نویسی مستقل از پلتفرم با استفاده از .NET Core و C#
برنامه نویسی مستقل از پلتفرم با استفاده از .NET Core و C#
 
Introduction to the Android NDK
Introduction to the Android NDKIntroduction to the Android NDK
Introduction to the Android NDK
 
Dotnet framework
Dotnet frameworkDotnet framework
Dotnet framework
 
"Making OpenCV Code Run Fast," a Presentation from Intel
"Making OpenCV Code Run Fast," a Presentation from Intel"Making OpenCV Code Run Fast," a Presentation from Intel
"Making OpenCV Code Run Fast," a Presentation from Intel
 
Dennis Benkert & Matthias Lübken - Patterns in a containerized world? - code....
Dennis Benkert & Matthias Lübken - Patterns in a containerized world? - code....Dennis Benkert & Matthias Lübken - Patterns in a containerized world? - code....
Dennis Benkert & Matthias Lübken - Patterns in a containerized world? - code....
 
Ndk
NdkNdk
Ndk
 
Using the android ndk - DroidCon Paris 2014
Using the android ndk - DroidCon Paris 2014Using the android ndk - DroidCon Paris 2014
Using the android ndk - DroidCon Paris 2014
 

Similar to Legacy of Void*

02 c++g3 d
02 c++g3 d02 c++g3 d
02 c++g3 dmahago
 
Introduction-to-C-Part-1.pdf
Introduction-to-C-Part-1.pdfIntroduction-to-C-Part-1.pdf
Introduction-to-C-Part-1.pdfAnassElHousni
 
Introduction-to-C-Part-1.pptx
Introduction-to-C-Part-1.pptxIntroduction-to-C-Part-1.pptx
Introduction-to-C-Part-1.pptxNEHARAJPUT239591
 
Introduction-to-C-Part-1 JSAHSHAHSJAHSJAHSJHASJ
Introduction-to-C-Part-1 JSAHSHAHSJAHSJAHSJHASJIntroduction-to-C-Part-1 JSAHSHAHSJAHSJAHSJHASJ
Introduction-to-C-Part-1 JSAHSHAHSJAHSJAHSJHASJmeharikiros2
 
Introduction-to-C-Part-1 (1).doc
Introduction-to-C-Part-1 (1).docIntroduction-to-C-Part-1 (1).doc
Introduction-to-C-Part-1 (1).docMayurWagh46
 
C++ helps you to format the I/O operations like determining the number of dig...
C++ helps you to format the I/O operations like determining the number of dig...C++ helps you to format the I/O operations like determining the number of dig...
C++ helps you to format the I/O operations like determining the number of dig...bhargavi804095
 
Introduction to .NET by QuontraSolutions
Introduction to .NET by QuontraSolutionsIntroduction to .NET by QuontraSolutions
Introduction to .NET by QuontraSolutionsQUONTRASOLUTIONS
 
Unit 1 of c++ part 1 basic introduction
Unit 1 of c++ part 1 basic introductionUnit 1 of c++ part 1 basic introduction
Unit 1 of c++ part 1 basic introductionAKR Education
 
Advance Android Application Development
Advance Android Application DevelopmentAdvance Android Application Development
Advance Android Application DevelopmentRamesh Prasad
 
tybsc it asp.net full unit 1,2,3,4,5,6 notes
tybsc it asp.net full unit 1,2,3,4,5,6 notestybsc it asp.net full unit 1,2,3,4,5,6 notes
tybsc it asp.net full unit 1,2,3,4,5,6 notesWE-IT TUTORIALS
 
Summer training PPT Manasv Singharia.pptx
Summer training PPT Manasv Singharia.pptxSummer training PPT Manasv Singharia.pptx
Summer training PPT Manasv Singharia.pptxshokeenk14
 
Hacking the Kinect with GAFFTA Day 1
Hacking the Kinect with GAFFTA Day 1Hacking the Kinect with GAFFTA Day 1
Hacking the Kinect with GAFFTA Day 1benDesigning
 
Introduction to .net framework
Introduction to .net frameworkIntroduction to .net framework
Introduction to .net frameworkArun Prasad
 
ASP.NET Session 1
ASP.NET Session 1ASP.NET Session 1
ASP.NET Session 1Sisir Ghosh
 
Introduction to .net FrameWork by QuontraSolutions
Introduction to .net FrameWork by QuontraSolutionsIntroduction to .net FrameWork by QuontraSolutions
Introduction to .net FrameWork by QuontraSolutionsQuontra Solutions
 
Bounded Model Checking for C Programs in an Enterprise Environment
Bounded Model Checking for C Programs in an Enterprise EnvironmentBounded Model Checking for C Programs in an Enterprise Environment
Bounded Model Checking for C Programs in an Enterprise EnvironmentAdaCore
 

Similar to Legacy of Void* (20)

02 c++g3 d
02 c++g3 d02 c++g3 d
02 c++g3 d
 
Introduction-to-C-Part-1.pdf
Introduction-to-C-Part-1.pdfIntroduction-to-C-Part-1.pdf
Introduction-to-C-Part-1.pdf
 
Introduction-to-C-Part-1.pptx
Introduction-to-C-Part-1.pptxIntroduction-to-C-Part-1.pptx
Introduction-to-C-Part-1.pptx
 
Introduction-to-C-Part-1 JSAHSHAHSJAHSJAHSJHASJ
Introduction-to-C-Part-1 JSAHSHAHSJAHSJAHSJHASJIntroduction-to-C-Part-1 JSAHSHAHSJAHSJAHSJHASJ
Introduction-to-C-Part-1 JSAHSHAHSJAHSJAHSJHASJ
 
C++Basics2022.pptx
C++Basics2022.pptxC++Basics2022.pptx
C++Basics2022.pptx
 
Introduction-to-C-Part-1 (1).doc
Introduction-to-C-Part-1 (1).docIntroduction-to-C-Part-1 (1).doc
Introduction-to-C-Part-1 (1).doc
 
C++ helps you to format the I/O operations like determining the number of dig...
C++ helps you to format the I/O operations like determining the number of dig...C++ helps you to format the I/O operations like determining the number of dig...
C++ helps you to format the I/O operations like determining the number of dig...
 
ewili13_submission_14
ewili13_submission_14ewili13_submission_14
ewili13_submission_14
 
Introduction to .NET by QuontraSolutions
Introduction to .NET by QuontraSolutionsIntroduction to .NET by QuontraSolutions
Introduction to .NET by QuontraSolutions
 
Unit 1 of c++ part 1 basic introduction
Unit 1 of c++ part 1 basic introductionUnit 1 of c++ part 1 basic introduction
Unit 1 of c++ part 1 basic introduction
 
Advance Android Application Development
Advance Android Application DevelopmentAdvance Android Application Development
Advance Android Application Development
 
tybsc it asp.net full unit 1,2,3,4,5,6 notes
tybsc it asp.net full unit 1,2,3,4,5,6 notestybsc it asp.net full unit 1,2,3,4,5,6 notes
tybsc it asp.net full unit 1,2,3,4,5,6 notes
 
Summer training PPT Manasv Singharia.pptx
Summer training PPT Manasv Singharia.pptxSummer training PPT Manasv Singharia.pptx
Summer training PPT Manasv Singharia.pptx
 
02 c++g3 d (1)
02 c++g3 d (1)02 c++g3 d (1)
02 c++g3 d (1)
 
Hacking the Kinect with GAFFTA Day 1
Hacking the Kinect with GAFFTA Day 1Hacking the Kinect with GAFFTA Day 1
Hacking the Kinect with GAFFTA Day 1
 
Introduction to .net framework
Introduction to .net frameworkIntroduction to .net framework
Introduction to .net framework
 
ASP.NET Session 1
ASP.NET Session 1ASP.NET Session 1
ASP.NET Session 1
 
Introduction to .net FrameWork by QuontraSolutions
Introduction to .net FrameWork by QuontraSolutionsIntroduction to .net FrameWork by QuontraSolutions
Introduction to .net FrameWork by QuontraSolutions
 
Bounded Model Checking for C Programs in an Enterprise Environment
Bounded Model Checking for C Programs in an Enterprise EnvironmentBounded Model Checking for C Programs in an Enterprise Environment
Bounded Model Checking for C Programs in an Enterprise Environment
 
Safety criticalc++
Safety criticalc++Safety criticalc++
Safety criticalc++
 

Recently uploaded

Post Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on IdentityPost Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on Identityteam-WIBU
 
Machine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their EngineeringMachine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their EngineeringHironori Washizaki
 
Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)Ahmed Mater
 
Cyber security and its impact on E commerce
Cyber security and its impact on E commerceCyber security and its impact on E commerce
Cyber security and its impact on E commercemanigoyal112
 
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...OnePlan Solutions
 
A healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfA healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfMarharyta Nedzelska
 
Odoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 EnterpriseOdoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 Enterprisepreethippts
 
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanySuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanyChristoph Pohl
 
Precise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalPrecise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalLionel Briand
 
Simplifying Microservices & Apps - The art of effortless development - Meetup...
Simplifying Microservices & Apps - The art of effortless development - Meetup...Simplifying Microservices & Apps - The art of effortless development - Meetup...
Simplifying Microservices & Apps - The art of effortless development - Meetup...Rob Geurden
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based projectAnoyGreter
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesPhilip Schwarz
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024StefanoLambiase
 
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company OdishaBalasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odishasmiwainfosol
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsAhmed Mohamed
 
Sending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdfSending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdf31events.com
 
Comparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfComparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfDrew Moseley
 
SpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at RuntimeSpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at Runtimeandrehoraa
 

Recently uploaded (20)

Post Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on IdentityPost Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on Identity
 
2.pdf Ejercicios de programación competitiva
2.pdf Ejercicios de programación competitiva2.pdf Ejercicios de programación competitiva
2.pdf Ejercicios de programación competitiva
 
Machine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their EngineeringMachine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their Engineering
 
Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)
 
Cyber security and its impact on E commerce
Cyber security and its impact on E commerceCyber security and its impact on E commerce
Cyber security and its impact on E commerce
 
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
 
A healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfA healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdf
 
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort ServiceHot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
 
Odoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 EnterpriseOdoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 Enterprise
 
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanySuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
 
Precise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalPrecise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive Goal
 
Simplifying Microservices & Apps - The art of effortless development - Meetup...
Simplifying Microservices & Apps - The art of effortless development - Meetup...Simplifying Microservices & Apps - The art of effortless development - Meetup...
Simplifying Microservices & Apps - The art of effortless development - Meetup...
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based project
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a series
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
 
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company OdishaBalasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML Diagrams
 
Sending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdfSending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdf
 
Comparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfComparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdf
 
SpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at RuntimeSpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at Runtime
 

Legacy of Void*

  • 1. Exiting the Dark Ages of Void* with C++11
  • 2. *YOU* are full of bullshit. C++ is a horrible language. It's made more horrible by the fact that a lot of substandard programmers use it, to the point where it's much much easier to generate total and utter crap with it. Quite frankly, even if the choice of C were to do *nothing* but keep the C++ programmers out, that in itself would be a huge reason to use C. -Linus Torvalds (2007) http://harmful.cat-v.org/software/c++/linus
  • 3. What is an embedded system? Well, a lot of different things, but generally speaking: ● Dedicated to a single purpose ● Minimalist approach to reduce cost ● “Always on” ● Has stiff reliability requirements ● uses safeguards like watchdogs for recovery
  • 4. Software selection based on hardware? Bare metal: ATtiny85, 8K of flash 512 byte of SRAM 512 bytes of EEPROM general- purpose OS (hopefully ruggedized) ● Bare metal or microkernel / RTOS ● Lots of C! (ok, NASA uses some ADA)
  • 5. Myths about C++ in embedded systems ● C++ code is slow compared to C ● C++ produces binaries too big for embedded systems ● Templates create too much code “bloat” ● Dynamic dispatch is slow. Virtual functions are too “heavyweight”. ● C++ is synonymous with dynamic allocation ● It’s too hard to port C++ to other architectures ● STL is the devil for embedded systems, therefore you shouldn’t use C++
  • 6. Myth #1: C++ is slow Truth: If you use C++ as “C with classes” you will get virtually indistinguishable performance. Other lightweight features add minimal overhead. Certain features of C++ can be too slow or otherwise unsuitable for certain embedded applications.
  • 7. Myth #2: C++ Binaries Are Too Big Truth: Using a reasonable subset of features leads to similar binary files sizes. Frequently, higher level abstractions can reduce copy/paste coding. libstdc++ is big. It’s also frequently not available!
  • 8. Myth #3: Templates create too much code bloat Truth: If you factor template independent code outside of your templates, you can minimize this effect. Every good C++ programmer knows this. Extensive use of macros in C produce bloat just as easily, with more obfuscation, and with less type safety.
  • 9. Myth #4: Dynamic Dispatch is “Slow” Truth: The overhead from virtual functions & vtables is actually pretty acceptable for almost all applications. ● one vtable per class (not per object) ● one pointer to the vtable per object ● one dereferencing operation per call (a couple cycles on most hardware) Virtual functions can be abused like any language feature. However, abstraction via interfaces (abstract classes in C++) is too powerful a tool for building APIs and testing code to ignore.
  • 10. Lulz http://freshbsd.org/commit/openbsd/8a6680833c42bde7de74b9ddb70bbad193c5359b “Why do we hide from the OpenSSL police, dad?” “Because they're not like us, son. They use macros to wrap stdio routines, for an undocumented (OPENSSL_USE_APPLINK) use case, which only serves to obfuscate the code.”
  • 11. Myth #5: C++ == dynamic allocation Truth: There is nothing about C++ that forces you to use dynamic allocation. If you don’t like the STL, don’t use it. The STL is a library not the language.
  • 12. Myth #6: C++ leads to non-portable code Truth: This used to be true. C++ compilers have made enormous strides in recent years for a number of reasons. Clang and GCC are now driving progress, and even MSVC++ is quite compliant to the standard. If you develop with multiple compilers frequently and avoid platform extensions, you’ll have excellent portability. C++ abstractions make it easier to separate platform-specific code.
  • 13. Lulz “I'm glad to know that Ultrix CC has a bug optimizing switch() statements lacking an explicit `case 0:' construct. But Ultrix has been dead for more than 15 years, really. Don't give it any reason to move out of its coffin.” http://freshbsd.org/commit/openbsd/111423c9d25cd2128223242f0a3d7dcaa9acb3b5
  • 14. Why is C++ “better now”? ● Renewed interest in native languages ● Clang (C-family front-end compiler for LLVM) has been pushing GCC to improve ● Coopetition between Intel/Microsoft/OSS tools to be “conformant” ● Many embedded vendors have switched from proprietary toolchains to GCC-based tools (expect even more to switch to Clang/LLVM)
  • 15. What is Clang/LLVM? LLVM is a language-agnostic compiler architecture. It separates language- specific lexing / early-stage compilation from the translation & optimization of specific targets. Interested in creating a new language? No problem, it will easily be able to target different architectures if your compile to LLVM. Interested in adding support for a new architecture? Great, you only have to translate LLVM instructions to your target.
  • 16. “Lightweight” C++ for MCUs (MISRA?) Free (no significant overhead vs. C) ● Classes ● Constructors / destructors & OOP modularity ● Single inheritance ● C++11 lambdas, constexpr, access modifiers ● templates (if factored appropriately) Cheap: ● Virtual methods Costly to some metric (performance / determinism / code size / runtime / memory / etc) ● dynamic allocation ● Virtual inheritance ● Run-time type information (RTTI == dynamic_cast<> & typeid) ● Exceptions
  • 17. How can C++ improve robustness/security? ● More powerful abstractions o private members - data hiding / encapsulation o const correctness - enforce immutability o deterministic destructors - guaranteed resource release ● Wrappers to that mediate access to dangerous resources o e.g. buffer views (wrappers) ● Better type-safety means that you make fewer assumptions in code. ● Powerful design patterns can be applied to encourage better practices
  • 18. Simple pattern, big effect: RAII The Problem (pseudo code in C) int stupidprefix_some_function_that_returns_error_code(.... arguments) { int err = 0; stupidprefix_acquire_resource(&resource); stupidprefix_do_stuff_with_resource(&resource); // … yada yada lots of code branches that require resource // from which you can’t return (hint: use GOTO) CLEANUP: stupidprefix_release_resource(&resource); return err; }
  • 19. C++ version w/ RAII namespace kickasswehavenamespaces { int some_function_that_returns_error_code(.... arguments) { Acquisition mediator(raw_resource); do_stuff_with_resource(mediator); //... Code branches //... Any return calls mediator’s destructor return 0; } } The act of acquiring a resource guarantees its release. “Resource Acquisition Is Initialization”. Java doesn’t even have an acceptable substitute. C# has “using” statement.
  • 20. “embeddable” C++11 features ● static_assert - Compile time assertions complete with custom compiler error messages. Ensure that your library is being configured with safe constants / types. ● constexpr - Compile time calculations (yet another Turing complete metaprogramming language) ● Access modifiers for method (override final)
  • 21. What specific design aims guided the committee? “Improve performance and ability to work directly with hardware -- make C++ even better for embedded systems programming and high- performance computation.” http://www.stroustrup.com/C++11FAQ.html
  • 22. So, dnp3 on Atmega2560? CPU: 8-bit AVR Max. Operating Freq. (MHz): 16 MHz SRAM: 8K Flash (Kbytes): 256 Kbytes https://github.com/automatak/dnp3/blob/2.0.x/embedded/atmelavr/demooutstation /main.cpp
  • 23. AVR DNP3 Demo ● C++11 using GCC 4.8.1 and 8-bit AVR backend ● USART only at this point ● Level 3 stack - more feature-rich than many RTUs / IEDs ● All statically allocated ● All interrupt based event-loop ● Makes use of AVR sleep mode ● SAv5? maybe possible? Definitely on ARM Cortex (Arduino DUE) ● Community members have been prototyping on TI ARM & PIC ● Need an interesting I/O shield to make a real “IED”