Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8735451
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T10:03:40+00:00 2026-06-13T10:03:40+00:00

The functions c32rtomb and mbrtoc32 from <cuchar> / <uchar.h> are described in the C

  • 0

The functions c32rtomb and mbrtoc32 from <cuchar>/<uchar.h> are described in the C Unicode TR (draft) as performing conversions between UTF-321 and “multibyte characters”.

(…) If s is not a null
pointer, the c32rtomb function determines the number of bytes needed to represent
the multibyte character that corresponds to the wide character given by c32
(including any shift sequences), and stores the multibyte character representation in
the array whose first element is pointed to by s. (…)

What is this “multibyte character representation”? I’m actually interested in the behaviour of the following program:

#include <cassert>
#include <cuchar>
#include <string>

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 = &converted[0];
    std::mbstate_t state {};
    for(auto u : u32) {
        ptr += std::c32rtomb(ptr, u, &state);
    }
    converted.resize(ptr - &converted[0]);
    assert(converted == narrow);
}

Is the assertion in it guaranteed to hold1?


1 Working under the assumption that __STDC_UTF_32__ is defined.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T10:03:42+00:00Added an answer on June 13, 2026 at 10:03 am

    For the assertion to be guaranteed to hold true it’s necessary that the multibyte encoding used by c32rtomb() be the same as the encoding used for string literals, at least as far as the characters actually used in the string.

    C99 7.11.1.1/2 specifies that setlocale() with the category LC_CTYPE affects the behavior of the character handling functions and the multibyte and wide character functions. I don’t see any explicit acknowledgement that the effect is to set the multibyte and wide character encodings used, however that is the intent.

    So the multibyte encoding used by c32rtomb() is the multibyte encoding from the default “C” locale.

    C++11 2.14.3/2 specifies that the execution encoding, wide execution encoding, UTF-16, and UTF-32 are used for the corresponding character and string literals. Therefore std::string narrow uses the execution encoding to represent that string.

    So is the “C” locale encoding of this string the same as the execution encoding of this string?

    C99 7.11.1.1/3 specifies that the “C” locale provides “the minimal environment” for C translation. Such an environment would include not only character sets, but also the specific character codes used. So I believe this means not only that the “C” locale must support the characters required in translation (i.e., the basic character set), but additionally that those characters in the “C” locale must use the same character codes.

    All of the characters in your string literals are members of the basic character set, and therefore converting the char32_t representation to the char “C” locale representation must produce the same sequence of values as the compiler produces for the char string literal; the assertion must hold true.

    I don’t see any suggestion that anything beyond the basic character set is supported in a compatible way between the execution encoding and the “C” locale, so if your string literal used any characters outside the basic character set then there would not be any guarantee that the assertion would hold. Even stipulating extended characters that exist in both the execution character set and the “C” locale, I don’t see any requirement that the representations match each other.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Should functions that act on and object, say to fill it out from xml,
Anonymous functions are available from PHP 5.3 . Should I use them or avoid
When I use functions inherited from C, like the ones in <cmath> or <cstdlib>
Callback functions are not executing from my form_validation config file when called upon. Am
Scalar-valued functions can be called from .NET as follows: SqlCommand cmd = new SqlCommand(testFunction,
What mysql functions are there (if any) to trim leading zeros from an alphanumeric
Without functions, I can do: DELETE FROM table1 WHERE something='hello' And my rows with
Some functions have a pointer argument that points to where a result from calling
FUNCTIONS.PHP <?php function global_header($page) { echo <!doctype html> <html lang='en'> <head> <meta charset='utf-8' />
Php functions strcmp , strcasecmp and other from this family are binary-safe. Are operators

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.