> Markdown version of [/videos/441-c-in-constrained-environments?t=172](https://www.wearedevelopers.com/videos/441-c-in-constrained-environments?t=172). Every page supports `.md` or `Accept: text/markdown`. Links point to the HTML versions so they work for humans too. Agent guide: [/agents.md](https://www.wearedevelopers.com/agents.md). --- # C++ in constrained environments Stop defaulting to restrictive C subsets for embedded systems. Expressive C++ abstractions actually help the compiler generate highly efficient code. Shift your computation to compile time today. - **Speakers:** Bjarne Stroustrup - **Event:** World Congress 2022 - **Published:** June 15, 2022 - **Duration:** 1:00:16 - **URL:** https://www.wearedevelopers.com/videos/441-c-in-constrained-environments ## Summary C++ in constrained environments—spanning embedded systems, hard real-time applications, and ultra-low latency infrastructure—demands a tunable approach rather than defaulting to the restrictive C language subset. By utilizing the "onion principle," developers should construct clean, high-level interfaces first, only peeling back layers for hardware-specific tuning and lower-level abstractions when performance strictly requires it. This strategy disproves the common misconception that modern programming inherently relies on bloated class hierarchies or excessive dynamic memory allocation, proving instead that expressive abstractions actually give the compiler's optimizer the context it needs to generate highly efficient code. Maximizing safety and performance involves shifting computational burdens from runtime to compile time through features like `constexpr` and `consteval`. Modern vocabulary types dramatically reduce undefined behavior; for instance, `std::span` bundles pointers with their size limits to naturally eliminate out-of-bounds access and redundant runtime range checks, while `std::variant` provides a type-safe alternative to traditional unions. Fundamental resource stability relies on RAII (Resource Acquisition Is Initialization), guaranteeing predictable and deterministic cleanup without the bloated memory footprint or unpredictable latency spikes associated with garbage collection. By adhering to the C++ Core Guidelines and enforcing rules via static analysis, teams can systematically eradicate vulnerabilities like resource-owning raw pointers without sacrificing raw speed. Robust systems also require heavily articulated policies for error handling and concurrency. Exceptions impose zero overhead on the "happy path" and are uniquely suited for rare, non-local failures such as constructor constraints, whereas error codes remain faster for expected, frequently occurring issues that can be handled locally. In highly concurrent environments, relying on the formal C++ memory model and leaning on type-safe atomic operations prevents catastrophic data races far more cheaply than utilizing coarse, OS-bound mutexes. Code clarity directly impacts performance; avoiding unnecessarily clever syntax ensures that both future human maintainers and compiler optimizers can reliably process and refine the system. **Keywords:** embedded systems programming, hard real-time constraints, compile-time evaluation, resource acquisition is initialization, deterministic memory management, c++ core guidelines, static analysis enforcement, std::span memory safety, std::variant type bounds, zero-overhead error handling, exception handling strategies, concurrent data races, lock-free atomics, zero-cost abstractions, low-latency optimization ## Chapters 1. **Defining hardware limitations inside varying constrained environments** (00:11) — How varying restrictions like power, memory capacity, and processing hardware continuously impact software scaling decisions. 1. **Dispelling common optimization and runtime performance misconceptions** (02:52) — Why subsetting language feature sets or fearing class hierarchies ultimately produces strictly unoptimized and error-prone configurations. 1. **Designing versatile software interfaces using the onion principle** (05:42) — Providing clean abstraction layers directly enables maintaining high-level interfaces while permitting unconstrained hardware access later. 1. **Mapping structural hardware models around fundamental storage mechanics** (06:59) — The straightforward mechanism of memory composition reliably maps objects onto compact sequential layouts across designated storage boundaries. 1. **Accelerating structured resource acquisition across customized object properties** (10:16) — Employing constructors and destructors guarantees resource destruction scales inherently through basic types alongside customized object configurations. 1. **Substituting restricted language constructs with standardized type constraints** (14:38) — Replacing structurally dangerous types like unions with standardized variants permanently enforces strict type validity and runtime scrutiny. 1. **Eradicating implicit array bounds faults deploying parameter spans** (17:39) — Combining pointers tightly to array parameters completely eradicates redundant bounds checking loops and hidden iteration flaws. 1. **Migrating advanced mathematical computation safely into compile evaluations** (22:28) — Shifting evaluation toward constant expressions and customized literal operators moves validation delays strictly to standard compile periods. 1. **Modernizing legacy programming architectures using iterative core guidelines** (29:02) — Enforcing specialized rules via static checkers separates modern safe components seamlessly without damaging established codebases. 1. **Constructing deliberate error handling paradigms matching variable dependencies** (35:25) — Selecting actively between system exceptions, native error returns, or execution termination depends definitively on environmental validation context. 1. **Preventing data races executing isolated lock-free standard structures** (47:07) — Standardized formal memory models enforce that lock-free atomic routines interact transparently alongside integrated standardized worker threads. 1. **Implementing modern language feature advancements carefully alongside readability** (50:50) — Creating readable standard logic proactively improves integration capabilities by assisting automated compilers tracking sequential execution steps. 1. **Exploring runtime testing validations and scheduled upcoming iterations** (52:55) — Assessing when developers should execute expected local state testing while identifying scope adjustments postponing updated release timelines. ## Related Moments - [Navigating emerging hardware standardization in vendor programming ecosystems](https://www.wearedevelopers.com/videos/859-accelerating-python-on-gpus) (from "Accelerating Python on GPUs") - [Optimizing execution with compact layouts and compile-time computation](https://www.wearedevelopers.com/videos/526-the-design-and-evolution-of-c) (from "The Design and Evolution of C++") - [History of C++ technical debt and language design](https://www.wearedevelopers.com/videos/847-eternal-sunshine-of-the-spotless-programming-language) (from "Eternal Sunshine of the Spotless Programming Language") - [Bridging hardware manipulation and high-level object abstractions](https://www.wearedevelopers.com/videos/181-101-brilliant-things-of-c) (from "101 brilliant things of C++") - [Key principles for engineering compliance and speed](https://www.wearedevelopers.com/videos/1426-great-devex-and-regulatory-compliance-possible) (from "Great DevEx and Regulatory Compliance - Possible?") - [Memory safety and component interoperability across disparate languages](https://www.wearedevelopers.com/videos/972-webassembly-the-next-frontier-of-cloud-computing) (from "WebAssembly: The Next Frontier of Cloud Computing") ## Related Articles - [How to Avoid Over-Engineering](https://www.wearedevelopers.com/magazine/546-how-to-avoid-over-engineering) - [4 reasons why you should learn Rust in 2021 – and maybe even have fun doing it](https://www.wearedevelopers.com/magazine/35-4-reasons-why-you-should-learn-rust-in-2021-and-maybe-even-have-fun-doing-it) - [Dev Digest 138 - Are you secure about this?](https://www.wearedevelopers.com/magazine/486-dev-digest-138-are-you-secure-about-this) - [Building AI Solutions with Rust and Docker](https://www.wearedevelopers.com/magazine/494-building-ai-solutions-with-rust-and-docker) ## Related Jobs - [Senior Architect Realtime Bare-Metal Software](https://www.wearedevelopers.com/jobs/ext/381559-senior-architect-realtime-bare-metal-software) at **ZEISS Group** - [Principal Software Engineer, Database Infrastructure](https://www.wearedevelopers.com/jobs/ext/1465908-principal-software-engineer-database-infrastructure) at **GitHub** - [Senior Software Engineer](https://www.wearedevelopers.com/jobs/ext/15942-senior-software-engineer) at **GitHub** - [Principal Software Engineer, Enterprise AI Platform](https://www.wearedevelopers.com/jobs/ext/1467292-principal-software-engineer-enterprise-ai-platform) at **GitHub** - [Hardware-naher Algorithmenentwickler](https://www.wearedevelopers.com/jobs/ext/1684535-hardware-naher-algorithmenentwickler) at **ZEISS Group** - [Senior Software Engineer, Enterprise Products](https://www.wearedevelopers.com/jobs/ext/1841248-senior-software-engineer-enterprise-products) at **GitHub**