C++ 9 min read

The NSA Told Developers to Leave C++. Embedded Is Why Most Didn't

Share this article
The NSA Told Developers to Leave C++. Embedded Is Why Most Didn't

What the NSA actually said

In November 2022 the NSA published guidance urging developers to move from memory-unsafe languages such as C and C++ to memory-safe ones such as C#, Go, Java, Ruby, Rust and Swift. Government agencies in the US and elsewhere repeated the message, and by 2024 "stop writing C++" had become a common headline.

The guidance rests on a real finding: memory errors (buffer overflows, use-after-free, out-of-bounds reads) account for a large share of serious vulnerabilities in big, long-lived codebases. Nobody serious disputes that. The open question is what to do about the code that already exists, and about the places where the memory-safe options do not fit.

The message did not stop at one document. This sequence shaped the debate:

  • November 2022: the NSA's "Software Memory Safety" information sheet names C and C++ as languages that leave memory management to the programmer, and recommends memory-safe languages.
  • December 2023: CISA, the FBI and partner agencies publish "The Case for Memory Safe Roadmaps" and ask manufacturers to publish how they will reduce memory-safety defects. Later CISA guidance set the start of 2026 as the date for those roadmaps.
  • February 2024: the White House Office of the National Cyber Director publishes a report on secure building blocks for software that names memory safety as a priority.
  • 2025: NSA and CISA follow up with joint guidance on adopting memory-safe languages.

The statistic behind all of it is the claim, reported by Microsoft and by the Chromium team, that roughly 70% of their serious security bugs were memory-safety issues. Those are very large desktop and browser codebases with huge attack surfaces. The figure says a lot about those projects and less about a motor controller with no network stack.

The guidance itself is more nuanced than the headlines. It accepts that changing language is not always possible, and it lists other mitigations: fuzzing, static analysis, sanitizers and hardened builds. Those are the tools embedded C++ teams already rely on.

C++ is still here, and embedded is a main reason

Four years on, C++ has not retreated. It remains one of the most widely used languages in industry rankings, and its standard keeps moving on a three-year cycle. A large part of that staying power comes from embedded systems: automotive ECUs, medical devices, industrial controllers, avionics, robotics, network gear and consumer electronics.

These are the places where a rewrite is hardest to justify. The code runs for ten to twenty years, the hardware has kilobytes or a few megabytes of memory, and every change goes through certification. A language that cannot fit those constraints is not an option, however safe it is.

Each embedded domain brings its own safety standard, and C and C++ are the languages those standards were written around.

DomainTypical standardTypical constraint
AutomotiveISO 26262, MISRA, AUTOSARMicrocontrollers with KB to MB of memory, 15-year support
AvionicsDO-178CCertified toolchains, deterministic timing
Medical devicesIEC 62304Traceability, long regulatory review per change
Industrial controlIEC 61508Hard real-time loops, 20+ year lifetime
RailEN 50128Safety integrity levels, proven-in-use code

Every one of these industries has a large installed base of C and C++ and a certification process tied to specific code. Replacing the language means redoing that evidence, not only the code. That cost, more than habit, keeps the code in C++.

Why embedded teams keep choosing C++

  • Deterministic cost. No garbage collector and no hidden runtime. Timing and memory use can be reasoned about and measured, which hard real-time work requires.
  • Zero-overhead abstractions. Templates, constexpr and RAII give structure without a runtime price, so firmware can be written at a high level and still fit in flash.
  • Direct hardware access. Memory-mapped registers, interrupts, linker scripts and custom allocators are everyday tools, not workarounds.
  • C compatibility. Vendor SDKs, HALs and RTOSes ship as C. C++ calls them directly, so teams adopt it one module at a time.
  • Toolchain reach. GCC and Clang target nearly every architecture on the market, including ones with no other mainstream language support.
  • Certification history. Standards such as MISRA C++ and AUTOSAR C++14 (now merged into MISRA C++:2023) and tools qualified for ISO 26262 and DO-178C exist for C++. A new language starts with none of that.

None of this means Rust is absent from embedded. It is growing there, with the embedded-hal ecosystem and a qualified compiler toolchain for safety work, and it is a good choice for new components. But most teams adopt it beside existing C++ instead of replacing it, so the C++ keeps being written, reviewed and maintained for years. Mixed codebases also make the boundary between the two languages a place where safety checks matter.

How embedded shaped modern C++

Embedded needs have pushed the language toward safer, leaner code for more than a decade. Several features exist because constrained-systems users asked for them.

  • C++11: constexpr, std::array, move semantics and smart pointers. std::unique_ptr gives ownership without a garbage collector.
  • C++14 to C++17: relaxed constexpr, std::optional, std::variant and std::string_view, which model absence, alternatives and borrowed text without heap allocation.
  • C++20: constinit, consteval, concepts and std::span, so more checks move to compile time and buffers travel with their size.
  • C++23: std::mdspan and std::expected, an error-handling type that works with exceptions disabled, which many embedded builds require.

One caution, because this point is often overstated: std::span, std::string_view and std::mdspan are not bounds-checked by default. They make the size explicit and are easier to check, but safety comes from enabling hardened library modes or using .at()-style checks. Fixed-capacity containers are also still arriving: std::inplace_vector is a C++26 addition, so earlier standards rely on libraries such as ETL.

A small example shows the style embedded teams favour: no heap, a fixed capacity, and the failure path visible in the type.

template <std::size_t N>
std::expected<std::span<const std::byte>, Error>
read_frame(const RingBuffer<N>& rb, std::size_t len) {
    if (len > rb.size()) return std::unexpected(Error::Underrun);
    return rb.view(len);   // borrowed view, no copy, no allocation
}

The capacity is a compile-time constant, ownership is explicit, and the caller must handle the error. None of it needs a runtime or a heap, which is why this style fits a microcontroller. Compilers and the hardened-library options in recent standard libraries also add optional bounds checks for builds that can afford them.

Memory safety without a rewrite

Embedded teams have been managing memory risk in C++ for years, mostly by removing the dangerous features instead of switching languages.

  • No heap after startup. Static allocation, pools and fixed-capacity containers remove use-after-free and fragmentation by construction.
  • A coding standard. MISRA C++:2023, AUTOSAR guidelines or the C++ Core Guidelines, enforced by tooling, not by review alone.
  • Warnings, sanitizers and static analysis in CI. AddressSanitizer and UBSan on host builds, plus clang-tidy or a commercial analyzer on every commit.
  • Measured memory. Flash, RAM and worst-case stack come from the linker map and call graph, and budgets fail the build when exceeded.
  • Quality gates on the codebase. Rules such as "no raw new/delete", "no unbounded recursion" and "no dependency cycles between modules" are written once and checked on every build.

This is where code analysis tools such as CppDepend fit: its CQLinq rules and quality gates express those constraints as queries over the whole codebase, and its memory views connect map-file data to individual functions. The point is not the tool, but the practice: safety in embedded C++ is a property of the process around the language.

Two practices in that list are worth a closer look, because they are where the NSA's concern and embedded reality meet.

Banning the risky subset. MISRA C++:2023 and the Core Guidelines remove or restrict the features behind most memory errors: raw owning pointers, unchecked array indexing, unbounded recursion, dynamic allocation after initialisation. The result is a language subset where the common bug classes are hard to write. It is not a guarantee, but it moves much of the safety argument from "trust the developer" to "check the rule".

Knowing where the memory goes. On a device with 256 KB of flash, an unexpected 20 KB function matters as much as an out-of-bounds read. Teams read the linker map, track flash and RAM per module and per function, and set budgets per release. Worst-case stack depth from compiler stack-usage output and the call graph covers the one resource that no heap rule protects. When these numbers sit in the same tool as the code, a regression in size or stack becomes a failed build and not a field surprise.

Conclusion

The memory-safety push is right about the problem and incomplete about the answer. For new, connected, internet-facing software, memory-safe languages are often the better choice. For the large body of embedded code that runs on tiny, certified, long-lived devices, C++ remains the practical option, and the industry keeps improving it for exactly that audience.

That is why embedded matters to C++'s popularity: it supplies the users with the strictest constraints, and their demands keep the language lean and safer. What does your team do today to keep C++ memory-safe: a standard, sanitizers, quality gates, or a gradual move to Rust?