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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T22:17:30+00:00 2026-06-16T22:17:30+00:00

I have read this related question , but it does not quite help me.

  • 0

I have read this related question, but it does not quite help me.

The goal of the Enum is to contain raw UTF-8 code (not the unicode code point) of single UTF-8 characters within the 4 byte range.

The following example works because the xcode source file is in UTF-8 format (which is the recommended encoding for xcode). It compiles and runs with the correct expected values.
But I also get the warning “character constant too long for this type”. Might I suppress it?.. or bad idea?

typedef enum {
    TEST_VAL_1BYTE = ',', // 0x2C
    TEST_VAL_2BYTE = '§', // 0xC2A7     (the warning)
    TEST_VAL_3BYTE = '✓', // 0xE29C93   (the warning)
    TEST_VAL_4BYTE = '', // 0xF09D8DA5 (the warning)
} TEST_VALUES_UTF8;

Safest way and without warnings, but it is more tedious to code:

typedef enum {
    NUM_VAL_1BYTE = 0x2C,       // ,
    NUM_VAL_2BYTE = 0xC2A7,     // §
    NUM_VAL_3BYTE = 0xE29C93,   // ✓
    NUM_VAL_4BYTE = 0xF09D8DA5, // 
} TEST_VALUES_UTF8;

Finally please note that enumeration with 1 or 4 ASCII characters is valid and without warnings:

enum {
    ENUM_TEST_1     = '1',     // 0x31        (no warning)
    ENUM_TEST_12    = '12',    // 0x3132      (w: multi-character character constant)
    ENUM_TEST_123   = '123',   // 0x313233    (w: multi-character character constant)
    ENUM_TEST_1234  = '1234',  // 0x31323334  (no warning)
};

Is there maybe a preprocessor macro that is source encoding generic that can return the UTF-8 code:

enum {
    TEST_VAL_2BYTE = AWESOME_UTF8CODE_MACRO('§'), // 0xC2A7
};

Thanks;

  • 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-16T22:17:31+00:00Added an answer on June 16, 2026 at 10:17 pm

    Use C++11 constexpr and u8 prefix, a’la http://liveworkspace.org/code/3EtxVE :

    #include <iostream>
    #include <cstdint>
    
    constexpr uint32_t utf8(const char (&c)[2]) {
       return uint8_t(c[0]);
    }
    constexpr uint32_t utf8(const char (&c)[3]) {
       return uint8_t(c[1]) | (uint8_t(c[0])<<8);
    }
    constexpr uint32_t utf8(const char (&c)[4]) {
       return uint8_t(c[2]) | (uint8_t(c[1])<<8) | (uint8_t(c[0])<<16);
    }
    constexpr uint32_t utf8(const char (&c)[5]) {
       return uint8_t(c[3]) | (uint8_t(c[2])<<8) | (uint8_t(c[1])<<16) | (uint8_t(c[0])<<24);
    }
    
    typedef enum {
        TEST_VAL_1BYTE = utf8(u8","),
        TEST_VAL_2BYTE = utf8(u8"§"),
        TEST_VAL_3BYTE = utf8(u8"✓"),
        TEST_VAL_4BYTE = utf8(u8""),
    } TEST_VALUES_UTF8;
    
    int main() {
       std::cout << std::hex << TEST_VAL_1BYTE << std::endl;
       std::cout << std::hex << TEST_VAL_2BYTE << std::endl;
       std::cout << std::hex << TEST_VAL_3BYTE << std::endl;
       std::cout << std::hex << TEST_VAL_4BYTE << std::endl;
    }
    

    which outputs

    2c
    c2a7
    e29c93
    f09d8da5

    If you don’t have access to u8 prefix you can simply ensure the source file is encoded in UTF-8, and I guess you can turn the constexpr into macros if needed…but shown is a clean way.

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

Sidebar

Related Questions

I have read this question but it's not quite what I was looking for.
I have read this question and the simple and clear answer but it's not
I have searched here, GooBingHooVista'd the world and read this related question for VS
I have read a lot of related topics here regarding this problem but I
I have read this thread when I got the the git: command not found
Please read the whole question; I personally think that this is programming-related; if you
This maybe a related question: Java assignment issues - Is this atomic? I have
I'm relatively(read: stupid newbie) familiar with disassembly but this bit stumped me: I have
This issue was reported several times, but still not resolved yet. I read all
Not really a programming related question but... I'd like very much to experiment with

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.