title: What is your favorite C programming trick?
body: <p>For example, I recently came across this in the linux kernel:</p>
  
  <pre>
  /* Force a compilation error if condition is true */
  #define BUILD_BUG_ON(condition) ((void)sizeof(char[1 - 2*!!(condition)]))
  </pre>
  
  <p>So, in your code, if you have some structure which must be, say a multiple of 8 bytes in size, maybe because of some hardware constraints, you can do:</p>
  
  <pre>
  BUILD_BUG_ON((sizeof(struct mystruct) % 8) != 0);
  </pre>
  
  <p>and it won't compile unless the size of struct mystruct is a multiple of 8, and if it is a multiple of 8, no runtime code is generated at all.</p>
  
  <p>Another trick I know is from the book "Graphics Gems" which allows a single header file to both declare and initialize variables in one module while in other modules using that module, merely declare them as externs.</p>
  
  <pre>
  #ifdef DEFINE_MYHEADER_GLOBALS
  #define GLOBAL
  #define INIT(x, y) (x) = (y)
  #else
  #define GLOBAL extern
  #define INIT(x, y)
  #endif
  
  GLOBAL int INIT(x, 0);
  GLOBAL int somefunc(int a, int b);
  </pre>
  
  <p>With that, the code which defines x and somefunc does:</p>
  
  <pre>
  #define DEFINE_MYHEADER_GLOBALS
  #include "the_above_header_file.h"
  </pre>
  
  <p>while code that's merely using x and somefunc() does:</p>
  
  <pre>
  #include "the_above_header_file.h"
  </pre>
  
  <p>So you get one header file that declares both instances of globals and function prototypes where they are needed, and the corresponding extern declarations.</p>
  
  <p>So, what are your favorite C programming tricks along those lines?</p>