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;