Error C2196: value of case '?' already used

Well, a curious mistake when building with Visual Studio Ultimate 2012 (maybe a problem with ANSI, unicode, etc.) in the code ...

switch (input[index])
{
    case 'ื': // Alef Hebrew character
        if (/*conditional*/) 
        {
            // Do stuff.
        }
    break;

    case 'ื‘': // Beth Hebrew character
        if (/*conditional*/)
        {
            //Do stuff
        }
    break;

    default:
    {
            //Do some other stuff.
    }
    break;

}

The second parameter parameter generates ...

Error C2196: case value '?' already used

A simple fix, if possible.

+4
source share
3 answers

A character 'ื'cannot fit into a char. Usually this takes several bytes, therefore it 'ื'is a "multi-channel literal", like 'ab'(NOTE: a single reference is used).

A multi-channel literal is of type int and has a value defined by the implementation. And, a different multi-valued literal can have the same meaning as an infinite number of multi-character literals.

, -, 'ื', 'ื‘' '?', , ('?') case switch.

, wchar_t, .

char, ื char. , , , ื index input:

const int ONE = 1;
if (strncmp(input+index, "ื", sizeof("ื") - ONE) == 0) {
      // Alef Hebrew character
    if (/*conditional*/) 
    {
       // Do stuff.
    }
} else if (strncmp(input+index, "ื‘", sizeof("ื‘") - ONE) == 0) {
     // Beth Hebrew character
    if (/*conditional*/)
    {
        //Do stuff
    }
} else {
    // default:
    // Do 
}
0

, input wchar_t s, , .

PeterT :

utf-8, ื 0xD790 ื‘ is 0xD791, , input[index] char, 0xD7.

. (char ASCII, )


, L ( ).

case L'ื': // Alef Hebrew character
    if (/*conditional*/) 
    {
        // Do stuff.
    }
break;

case L'ื‘': // Beth Hebrew character
    if (/*conditional*/)
    {
        //Do stuff
    }
break;

, , Unicode, , .

unicode :

case L'\u05D0': // Aleph Hebrew character
// ...
case L'\u05D1': // Beth Hebrew character
+6

C ( ++), , . , - - char. char ( ) ASCII.

If you are using modern (read at least C ++ 11) versions of C ++, follow this answer .

If you use C, you probably want to use the IBM ICU library .

+3
source

Source: https://habr.com/ru/post/1653765/


All Articles