Difference between revisions of "C and C++ notes / Semi-sorted"

From Helpful
Jump to: navigation, search
m (assert.h)
m (Preprocessor)
Line 8: Line 8:
 
http://gcc.gnu.org/onlinedocs/cpp/
 
http://gcc.gnu.org/onlinedocs/cpp/
 
http://www.cs.cf.ac.uk/Dave/C/node14.html
 
http://www.cs.cf.ac.uk/Dave/C/node14.html
-->
 
  
 +
 +
 +
'''Comments on #preprocessor lines'''
 +
 +
Are turned into a space before interpetation,
 +
which typically has no effect.
 +
 +
https://stackoverflow.com/questions/33574477/are-comments-allowed-on-the-same-line-as-preprocessor-directives-and-what-is-the
 +
 +
-->
  
 
==Debugging==
 
==Debugging==

Revision as of 16:53, 18 June 2020

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 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?