</>EmbeddedInterview

What is the difference between #include <file> and #include "file"?

EasyC Programming

Short answer: #include <file> searches only the system include directories and those given with -I. #include "file" first looks in the directory of the file that contains the #include, then falls back to the same paths as <file>. Use quotes for your project's own headers and angle brackets for the standard library and third-party SDK headers.

Search order with GCC

Form Searched
"file.h" directory of the current file → -iquote dirs → -I dirs → system dirs
<file.h> -I dirs → -isystem dirs → system dirs (e.g. the toolchain's include/)

See the exact list with arm-none-eabi-gcc -xc -E -v /dev/null.

Why it matters

  • If your project has a header with the same name as a system one (e.g. config.h, time.h), quotes find yours first; angle brackets find the system one. Avoid such clashes.
  • Headers included with -isystem get fewer warnings, which is useful for noisy vendor code but can hide real problems.

Good include practice

  • Each header should be self-contained (include what it needs) and have include guards.
  • Each .c file includes its own header first, which proves the header is self-contained.
  • Do not put definitions (variables, non-inline functions) in headers.
  • Prefer forward declarations (struct uart;) over including big headers when only a pointer is needed; it speeds up builds and reduces coupling.

Embedded note: vendor SDKs (CMSIS, STM32 HAL, nRF SDK) are usually added with -I, and you include them with angle brackets or quotes depending on the project's convention. Consistency matters more than the choice.