title: How to convert concatenated strings to wide-char with the C preprocessor?
body: <p>I am working on a project where I have many constant strings formed by concatenation (numbers, etc.).</p>
  
  <p>For example, I have a <code>LOCATION</code> macro that formats <code>__FILE__</code> and <code>__LINE__</code> into a string that I can use to know where I am in the code, when printing messages or errors:</p>
  
  <pre><code>#define _STR(x)    # x
  #define STR(x)     _STR(x)
  #define LOCATION __FILE__ "(" STR(__LINE__) ")"
  </code></pre>
  
  <p>So, this would format a location like "file.cpp(42)". The problem is when I try to convert the result to a wide-string:</p>
  
  <pre><code>#define _WIDEN(x)  L ## x
  #define WIDEN(x)   _WIDEN(x)
  #define WLOCATION  WIDEN(LOCATION)
  </code></pre>
  
  <p>This works just fine with GCC, and results in L"file.cpp(42)" being inserted in my code. However, when trying this with MSVC++ (using Visual C++ 2008 Express), I get an error:</p>
  
  <pre><code>error: Concatenating wide "file.cpp" with narrow "("
  </code></pre>
  
  <p>I understand that the <code>L</code> prefix gets added only to the first term in my expression. I've also tried this:</p>
  
  <pre><code>#define _WIDEN(x) L ## #x
  </code></pre>
  
  <p>Which "works", but gives the string <code>L"\"file.cpp\" \"(\" \"42\" \")\""</code> which is obviously not very convenient (and not what I am looking for), especially considering that this macro is simple compared to other macros.</p>
  
  <p>So, my question is: how can I get it to apply to the entire expression in MSVC++, so I can get the same result I am getting with GCC? I would rather not create a second string with all-wide tokens, because I would then have to maintain two macros for each one, which is not very convenient and can lead to bugs. Plus, I need the narrow version of each string as well, so using all-wide strings is not an option either, unfortunately.</p>