C and C++ notes / Semi-sorted

From Helpful
Revision as of 12:47, 20 May 2020 by Helpful (Talk | contribs)

Jump to: navigation, 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.


Preprocessor

Debugging

assert.h =

(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 having to wrap them in #ifndef NDEBUG ... #endif.

If an assert fails:

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



Optimization notes

Are unused variables optimized away?