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 7024831
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T23:53:38+00:00 2026-05-27T23:53:38+00:00

C++11 has two new character integral data types, char16_t and char32_t . I would

  • 0

C++11 has two new character integral data types, char16_t and char32_t. I would like to emulate them for compilers that don’t have a distinct type in order to overload I/O operations to see them a characters instead of their integer value.

These are the requirements:

  • Distinct (no typedef).
  • exact-width on normal systems (ala uint16_t and uint32_t)
  • other C++11 features are allowed (see below first attempt)
  • Must play nice with literals; char16_t c16 = u"blabla unicode text blabla"; must work.
  • if char16_t can be used in math operators, obviously this needs to function as well.

My first attempt which fails in the literal department was a strongly typed enum:

enum char16_t : uint16_t;

This has other drawbacks as well, that could perhaps be resolved by supplying the necessary operators myself (which is really fine by me).

  • 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-05-27T23:53:38+00:00Added an answer on May 27, 2026 at 11:53 pm

    I don’t think you will get the initialization to work because there isn’t much scope to get it to work. The problem is that the initialization you are using in your example isn’t supposed to work: the string literal u"..." yields an an array of char16_t const objects and you want to initialize a pointer with it:

    char16_t const* c16 = u"...";
    

    Also, without implementation of char16_t in the compiler it is very unlikely to support char16_t string literals. The best you could achieve is to play macro tricks which are intended to do the Right Thing. For now, you’d use e.g. wide character literals and when you get a compiler which support char16_t you just change the macro to use char16_t literals. Even for this to work you might need to use a record type which is bigger than 16 bit because wchar_t uses 32 bits on some platforms.

    #define CONCAT(a,b) a##b
    
    #if defined(HAS_C16)
    #  define C16S(s) CONCAT(u,s)
    #else
    #  define C16S(s) reinterpret_cast<char16_t const*>(CONCAT(L,s));
    struct char16_t
    {
        unsigned short value;
    };
    #endif
    
    
    int main()
    {
        char16_t const* c16 = C16S("...");
    }
    

    Obviously, you still need to provide all kinds of operators e.g. to make integer arithmetic and suitable conversions work.

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

Sidebar

Related Questions

Mysql has two types that can hold boolean data, bit and bool. Bit(1) seems
Imagine a table that has two fields, a smalltimedate and an int and about
why java Object class has two methods hashcode() and equals()? One of them looks
I have a table:'Categories' which has two fields:Category_ID and Category. Data in Category_ID field
I have two xml files, one of them is dev.xml which has this code
I have a simple has_one/belongs_to relationship between two models. This is a new association
Ruby has two different exceptions mechanisms: Throw/Catch and Raise/Rescue. Why do we have two?
PowerPoint has two kinds of shadows - shape and text. Shape shadows may be
My current development project has two aspects to it. First, there is a public
Python 2.x has two ways to overload comparison operators, __cmp__ or the rich comparison

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.