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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T11:03:49+00:00 2026-06-05T11:03:49+00:00

Why is there no UTF-8 character literal in C11 or C++11 even though there

  • 0

Why is there no UTF-8 character literal in C11 or C++11 even though there are UTF-8 string literals? I understand that, generally-speaking, a character literal represents a single ASCII character which is identical to a single-octet UTF-8 code point, but neither C nor C++ says the encoding has to be ASCII.

Basically, if I read the standard right, there’s no guarantee that '0' will represent the integer 0x30, yet u8"0" must represent the char sequence 0x30 0x00.

EDIT:

I’m aware not every UTF-8 code point would fit in a char. Such a literal would only be useful for single-octet code points (aka, ASCII), so I guess calling it an “ASCII character literal” would be more fitting, so the question still stands. I just chose to frame the question with UTF-8 because there are UTF-8 string literals. The only way I can imagine portably guaranteeing ASCII values would be to write a constant for each character, which wouldn’t be so bad considering there are only 128, but still…

  • 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-05T11:03:50+00:00Added an answer on June 5, 2026 at 11:03 am

    It is perfectly acceptable to write non-portable C code, and this is one of many good reasons to do so. Feel free to assume that your system uses ASCII or some superset thereof, and warn your users that they shouldn’t try to run your program on an EBCDIC system.

    If you are feeling very generous, you can encode a check. The gperf program is known to generate code that includes such a check.

    _Static_assert('0' == 48, "must be ASCII-compatible");
    

    Or, for pre-C11 compilers,

    extern int must_be_ascii_compatible['0' == 48 ? 1 : -1];
    

    If you are on C11, you can use the u or U prefix on character constants, but not the u8 prefix…

    /* This is useless, doesn't do what you want... */
    _Static_assert(0, "this code is broken everywhere");
    if (c == '々') ...
    
    /* This works as long as wchar_t is UTF-16 or UTF-32 or UCS-2... */
    /* Note: you shouldn't be using wchar_t, though... */
    _Static_assert(__STDC_ISO_10646__, "wchar_t must be some form of Unicode");
    if (c == L'々') ...
    
    /* This works as long as char16_t is UTF-16 or UCS-2... */
    _Static_assert(__STDC_UTF_16__, "char16_t must be UTF-16");
    if (c == u'々') ...
    
    /* This works as long as char32_t is UTF-32... */
    _Static_assert(__STDC_UTF_32__, "char32_t must be UTF-32");
    if (c == U'々') ...
    

    There are some projects that are written in very portable C and have been ported to non-ASCII systems (example). This required a non-trivial amount of porting effort, and there’s no real reason to make the effort unless you know you want to run your code on EBCDIC systems.

    On standards: The people writing the C standard have to contend with every possible C implementation, including some downright bizarre ones. There are known systems where sizeof(char) == sizeof(long), CHAR_BIT != 8, integral types have trap representations, sizeof(void *) != sizeof(int *), sizeof(void *) != sizeof(void (*)()), va_list are heap-allocated, etc. It’s a nightmare.

    Don’t beat yourself up trying to write code that will run on systems you’ve never even heard of, and don’t search to hard for guarantees in the C standard.

    For example, as far as the C standard is concerned, the following is a valid implementation of malloc:

    void *malloc(void) { return NULL; }
    

    Note that while u8"..." constants are guaranteed to be UTF-8, u"..." and U"..." have no guarantees except that the encoding is 16-bits and 32-bits per character, respectively, and the actual encoding must be documented by the implementation.

    Summary: Safe to assume ASCII compatibility in 2012.

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

Sidebar

Related Questions

You can write UTF-8/16/32 string literals in C++11 by prefixing the string literal with
Is there a portable way to convert a UTF-8 string in C to upper
Is there any way InputStream wrapping a list of UTF-8 String ? I'd like
A colleague tells me that there is no way to bulk insert UTF-8 encoded
I was wondering is there an article that discusses the rules for the character
I have a MySQL table using the UTF-8 character set with a single column
Is there a way to keep json_encode() from returning null for a string that
I have a plain text-file (.yml) that contains UTF-8 character sequences like this: foo:
What C/C++ Libraries are there for detecting the multi-byte character encoding (UTF-8, UTF-16, etc)
How to iterate a UTF-8 string character by character using indexing? When you access

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.