What Is Embedded C?
The same C language, used in a very different world: no operating system, a few kilobytes of RAM, and hardware you control directly through registers.
Embedded C is not a separate language. It is ISO C (usually C99 or C11) used to program microcontrollers, plus a handful of compiler extensions and a different set of habits. What changes is the environment: the program is the only software on the chip, it starts at power-up and never exits, memory is measured in kilobytes, and the inputs and outputs are pins and peripherals rather than a keyboard and a screen.
What embedded C adds on top of the C you know
int main(void) { setup(); loop(); return 0; } int main(void) { setup(); for (;;) { loop(); } }
On bare metal there is no OS to return to. If main returns, the startup code usually falls into an infinite loop or a fault handler, and the device appears dead.
printf("value=%d\n", v); // in a tight control loop Log rarely, or send a few bytes over UART from a buffer printf pulls in kilobytes of library code and can take milliseconds over a slow UART — enough to miss interrupts and deadlines.
Which standard headers must a freestanding C implementation provide?
At least <float.h>, <iso646.h>, <limits.h>, <stdalign.h>, <stdarg.h>, <stdbool.h>, <stddef.h>, <stdint.h> and <stdnoreturn.h> (C11). printf, malloc and file I/O are not guaranteed.
Why does main() in firmware contain an infinite loop?
The program is the only software on the device and runs as long as it has power. There is no operating system to return to, so main keeps servicing the hardware forever.
What is a cross-compiler?
A compiler that runs on one machine (the PC) but produces code for a different CPU architecture (for example ARM Cortex-M), such as arm-none-eabi-gcc.