Embedded C Cheat Sheet
Fixed-width types, bit manipulation, volatile, register access, promotion pitfalls and interrupt-safe patterns
Most embedded C bugs come from a small set of language details: an int that is 16 bits on one target and 32 on another, a shift into the sign bit, a missing volatile, a read-modify-write that races an interrupt, or a cast that breaks alignment. This cheat sheet collects the idioms that avoid them on a few pages you can keep beside the keyboard.
Code is shown as plain text in the style of C99 and later. Register names and addresses are illustrative; use the vendor device header (for example a CMSIS header on Arm Cortex-M) in real code. The coding checklist reflects the ideas behind guidelines such as MISRA C at a concept level only; it does not reproduce or replace any guideline.
What is inside
- Fixed-width and related types from stdint.h, stddef.h and stdbool.h
- Bit manipulation idioms: set, clear, toggle, test, masks and bit fields
- volatile and const: when to use each and how to read pointer declarations
- Register access patterns, including write-1-to-clear and set/reset registers
- Integer promotion, signedness and overflow pitfalls with examples
- Interrupt-safe patterns: flags, critical sections and ring buffers
- Common undefined behaviour and a coding-style checklist
Contents
- Fixed-width types
- Bit manipulation idioms
- volatile and const
- Register access patterns
- Integer promotion and overflow
- Interrupt-safe patterns
- Common undefined behaviour
- Coding-style checklist
- Notes and limits
Formats: PDF document. Sign in to download for free.
Related courses
Discuss your project
Email support@aavico.com or use Get in Touch when the website finishes loading.