title: Printing UTF-8 strings with printf - wide vs. multibyte string literals
body: <p>In statements like these, where both are entered into the source code with the same encoding (UTF-8) and the locale is set up properly, is there any practical difference between them?</p>
  
  <pre><code>printf("ο Δικαιοπολις εν αγρω εστιν\n");
  printf("%ls", L"ο Δικαιοπολις εν αγρω εστιν\n");
  </code></pre>
  
  <p>And consequently is there any reason to prefer one over the other when doing output? I imagine the second performs a fair bit worse, but does it have any advantage (or disadvantage) over a multibyte literal?</p>
  
  <p>EDIT: There are no issues with these strings printing. But I'm not using the wide string functions, because I want to be able to use <code>printf</code> etc. as well. So the question is are these ways of printing any different (given the situation outlined above), and if so, does the second one have any advantage?</p>
  
  <p>EDIT2: Following the comments below, I now know that this program works -- which I thought wasn't possible:</p>
  
  <pre><code>int main()
  {
      setlocale(LC_ALL, "");
      wprintf(L"ο Δικαιοπολις εν αγρω εστιν\n");  // wide output
      freopen(NULL, "w", stdout);                 // lets me switch
      printf("ο Δικαιοπολις εν αγρω εστιν\n");    // byte output
  }
  </code></pre>
  
  <hr>
  
  <p><strong>EDIT3</strong>: I've done some further research by looking at what's going on with the two types. Take a simpler string:</p>
  
  <pre><code>wchar_t *wides = L"£100 π";
  char *mbs = "£100 π";
  </code></pre>
  
  <p>The compiler is generating different code. The wide string is:</p>
  
  <pre><code>.string "\243"
  .string ""
  .string ""
  .string "1"
  .string ""
  .string ""
  .string "0"
  .string ""
  .string ""
  .string "0"
  .string ""
  .string ""
  .string " "
  .string ""
  .string ""
  .string "\300\003"
  .string ""
  .string ""
  .string ""
  .string ""
  .string ""
  </code></pre>
  
  <p>While the second is:</p>
  
  <pre><code>.string "\302\243100 \317\200"
  </code></pre>
  
  <p>And looking at the Unicode encodings, the second is plain UTF-8. The wide character representation is UTF-32. I realise this is going to be implementation-dependent.</p>
  
  <p>So perhaps the wide character representation of literals is more portable? My system will not print UTF-16/UTF-32 encodings directly, so it is being automatically converted to UTF-8 for output.</p>