Working with Strings in Embedded C++
This article discusses the use of strings in embedded systems. It explains how the need for and use of strings in embedded systems has changed with the advent of cheaper, full graphic displays and the growth of the ‘Internet of Things’ (IoT). The article also covers character literals, C-Strings and string literals, and the difference in memory models between them. It also highlights the safety and security issues that arise from using strings in embedded systems. Finally, it explains how C++11 introduced a Raw string literal type that is useful for storing file paths or regular expressions.
Summary
This article explains how string usage in embedded systems has evolved with cheaper displays and the growth of IoT, and surveys the common string types and memory models in embedded C++. It highlights safety and security pitfalls of string handling and shows how C++11 raw string literals can simplify storing paths and regular expressions in firmware.
Key Takeaways
- Differentiate between character literals, C-strings, string literals, and std::string and their memory/ownership implications on embedded platforms.
- Mitigate common safety and security issues by using bounds-checked APIs and design patterns to avoid buffer overflows and undefined behavior.
- Place string data appropriately (flash vs RAM) and apply platform-specific macros or attributes to reduce RAM usage.
- Use C++11 raw string literals to store file paths and regular expressions without complex escaping, simplifying firmware code.
Who Should Read This
Embedded firmware engineers and C++ developers working on resource-constrained devices or IoT products who want practical guidance on safer, more efficient string handling.
Still RelevantIntermediate
Related Documents
- Consistent Overhead Byte Stuffing TimelessIntermediate
- PID Without a PhD TimelessIntermediate
- Introduction to Embedded Systems - A Cyber-Physical Systems Approach Still RelevantIntermediate
- Can an RTOS be really real-time? TimelessAdvanced
- Memory Mapped I/O in C TimelessIntermediate








