title: What encoding does c32rtomb convert to?
body: <p>The functions <code>c32rtomb</code> and <code>mbrtoc32</code> from <code>&lt;cuchar&gt;</code>/<code>&lt;uchar.h&gt;</code> are described in the C Unicode TR (<a href="http://www.open-std.org/jtc1/sc22/WG14/www/docs/n1040.pdf" rel="noreferrer">draft</a>) as performing conversions between UTF-32<sup>1</sup> and "multibyte characters".</p>
  
  <blockquote>
    <p>(...) If <code>s</code> is not a null 
    pointer, the <code>c32rtomb</code> function determines the number of bytes needed to represent 
    the multibyte character that corresponds to the wide character given by <code>c32</code> 
    (including any shift sequences), and stores the multibyte character representation in 
    the array whose first element is pointed to by <code>s</code>. (...)</p>
  </blockquote>
  
  <p>What is this "multibyte character representation"? I'm actually interested in the behaviour of the following program:</p>
  
  <pre><code>#include &lt;cassert&gt;
  #include &lt;cuchar&gt;
  #include &lt;string&gt;
  
  int main() {
      std::u32string u32 = U"this is a wide string";
      std::string narrow  = "this is a wide string";
      std::string converted(1000, '\0');
      char* ptr = &amp;converted[0];
      std::mbstate_t state {};
      for(auto u : u32) {
          ptr += std::c32rtomb(ptr, u, &amp;state);
      }
      converted.resize(ptr - &amp;converted[0]);
      assert(converted == narrow);
  }
  </code></pre>
  
  <p>Is the assertion in it guaranteed to hold<sup>1</sup>?</p>
  
  <hr>
  
  <p><sup>1</sup> Working under the assumption that <code>__STDC_UTF_32__</code> is defined.</p>