title: Unit test C with compiler specific keywords
body: <p>I am writing unit tests for some embedded C, that run on a host machine (not testing on target yet) and compile with GCC. I have been using the Ceedling build system with the Unity testing framework to test.</p>
  
  <p>One of the files I would like to test includes a file (say a.h) that includes another file (say, cpu.h) that is part of the board support package from the embedded device vendor, and uses keywords specific to the target compiler (e.g. <code>__cregister</code>, such as in <code>extern __cregister volatile unsigned int IER;</code>.</p>
  
  <p>Another issue, again with such a file included from the BSP, is inline assembly <code>asm()</code> sections such as in <code>#define FOO_ASM asm("FOO")</code>.</p>
  
  <p>These both of course throws an error when building tests as GCC does not recognise these keywords. </p>
  
  <p>I had thought I could prevent these BSP headers from being added in by having Ceedling generate a mock, by adding <code>#include "mock_a.h"</code> to my test file, but GCC still compiles a.h, and thus b.h.</p>
  
  <p>Is there a best practice way of solving such issues?</p>
  
  <p>I could add something like the below to the BSP file in question, but I am loath to alter vendor code that would change or overwrite my changes with a new version release, I would rather understand how to isolate the unit properly.</p>
  
  <pre><code>// Unknown how __cregister is initially defined
  #ifdef TEST
      #undef __cregister // Redefine __cregister to nothing
      #define __cregister
  #endif
  
  extern __cregister volatile unsigned int IER;
  </code></pre>