title: Is it possible to get GCC to compile UTF-8 with BOM source files?
body: <p>I develop C++ cross platform using Microsoft Visual Studio on Windows and GCC on uBuntu Linux.</p>
  <p>In Visual Studio I can use unicode symbols like &quot;<strong>π</strong>&quot; and &quot;<strong>²</strong>&quot; in my code. Visual Studio always saves the source files as UTF-8 with BOM (Byte Order Mark).</p>
  <p>For example:</p>
  <pre><code>// A = π.r²
  double π = 3.14;
  </code></pre>
  <p>GCC happily compiles these files only if I remove the BOM first. If I do not remove the BOM, I get errors like these:</p>
  <blockquote>
  <p>wwga_hydutils.cpp:28:9: error: stray ‘\317’ in program</p>
  <p>wwga_hydutils.cpp:28:9: error: stray ‘\200’ in program</p>
  </blockquote>
  <p>Which brings me to the question:</p>
  <p>Is there a way to get GCC to compile UTF-8 files without first removing the BOM?</p>
  <hr />
  <p>I'm using:</p>
  <ul>
  <li>Windows 7</li>
  <li>Visual Studio 2010</li>
  </ul>
  <p>and:</p>
  <ul>
  <li>uBuntu Oneiric 11.10</li>
  <li>GCC 4.6.1 (as provided by <em>apt-get install gcc</em>)</li>
  </ul>
  <hr />
  <p><strong>Edit:</strong></p>
  <p>As the first commenter pointed out, my problem was <strong>not</strong> the BOM, but having non-ascii characters outside of string constants. GCC does not like non-ascii characters in symbol names, but it turns out GCC is fully compatible with UTF-8 with BOM.</p>