C and C++ notes / Semi-sorted

From Helpful
Jump to navigation Jump to search
Notes related to C and C++

Note: Some notes describe behaviour common to most variants - for C mostly meaning C89 (and a bit of C99), unless mentioned otherwise.




(ANSI-C, C99) (verify)

assert() statements (via preprocessor) that are only compiled in when NDEBUG is not defined.

This lets you have debug expressions that are automatically omitted from production, without explicitly wrapping them in #ifndef NDEBUG ... #endif.

If an assert fails:

  • error information is written to stderr (including __FILE__, __LINE__, __func__ if C99, and the assert expression as text)
  • abort() is called

Optimization notes

Are unused variables optimized away?