title: the best way to solve "variable 'xxx' was declared but never referenced"
body: <p><strong>-Pre-condition:</strong></p>
  
  <p>I know it has many ways to ignore this warning, but I do need fix it but NOT just add some flags for compiler to ignore it, because I can do this makefile <code>CFLAG</code> modification on my local, but the compile/build policy can NOT been changed due to company quality control reason. This question I just want to discus who to fix it in a good way but NOT ignore them, many thanks!</p>
  
  <p>Meanwhile, not ONLY some variables are never referenced, but also it has warning:</p>
  
  <pre><code>function 'xxx' was declared but never referenced
  </code></pre>
  
  <p>the similar problem in head file, it has some static functions, which ONLY use in one c file but many others c files include this head file.</p>
  
  <p><strong>Furthermore, this code run on a dedicate target, which has critical memory consumption, that means I need take care of each bit both in ROM and RAM.</strong></p>
  
  <p><strong>-------Problem shows in below-----------</strong></p>
  
  <p>I currently build some codes, which provide by vendor and it contains lots of warning, because I want to have a warning free build, therefore, I put <code>-Werror</code> for <code>gcc</code> and <code>--diag_error=[error_ref_number]</code> for <code>armcc</code>.</p>
  
  <p>After above makefile modification, the most warning I currently meet is</p>
  
  <pre><code>variable 'xxx' was declared but never referenced
  </code></pre>
  
  <p>It caused by following coding style:</p>
  
  <p>in <code>veryBIG.h</code>, it defined some variables like (just for example but the vendor's code has exactly the same way):</p>
  
  <pre><code>static const int a = 10;
  static const int b = 20;
  static const int c = 30;
  ...
  static const int z = xx;
  </code></pre>
  
  <p>however, many c files include this BIG head file, but ONLY one of these c file use one of above variables, it like <code>a.c</code> will use variable <code>a</code>, <code>b.c</code> use variable <code>b</code>, etc,.</p>
  
  <p>I have two ways to fix:</p>
  
  <ol>
  <li><p>move these kind of variables into it dedicate c file, and it means head file become useless</p></li>
  <li><p>separate head files, means I create <code>a.h</code>, <code>b.h</code>, ..., <code>z.h</code>, and each dedicate c file include ONLY one of above head file</p></li>
  </ol>
  
  <p>However, both of these two ways have limitation for my work,</p>
  
  <p><strong>Way 1</strong>: </p>
  
  <p>I'm NOT sure if vendor further update will change this head file to what or have some update values, because vendor do NOT want to fix this compile warnings, that means if I follow way 1, I will manually update these variables if it has been changed by vendor (ONLY in head file, and I must synchronize them to c file) and this way makes my further merge work become complicated</p>
  
  <p><strong>Way 2</strong>:</p>
  
  <p>It also makes my further merge work become NOT easy, because I do NOT use the vendor way and I also need modify the system makefile to adapt these head files into <code>INC</code> PATH if they are NOT locate in same folder (which the PATH already define for that <code>veryBIG.h</code>)</p>
  
  <p>If there any idea to overcome this problem?</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>I can temporary use <code>Wno-xxx</code> for <code>gcc</code> and delete some <code>[error_ref_number]</code> in flag <code>--diag_error</code> (like <code>CFLAG += --diag_error=550,223,188,177,....,</code>, and I delete <code>177</code> for pass this warning in <code>armcc</code>) and makes my compile go on and first fix others warnings, but I do need fix ALL warning.</p>