Found a bug the code below, it parses C-string and is supposed to detect UTF8 characters:
char* pTmp = ...;
...
switch (*pTmp)
{
case 'o':
{
... // works fine
break;
}
case 0xC2:
{
... // never gets triggered
break;
}
}
However case 0xC2:
is never triggered.
My assumption is that 0xC2
is considered an int
and therefore is 194 which is bigger than 127, the maximum value for char
data type. So -62 != 194
Or may be there is some overflow or integer promotion is happening here.
Writing switch ((unsigned char)*pTmp)
fixes the issue.
But I would like to clarify what is really going on here and what rules are applied.
I'm also open to changing the title, just nothing better came up in mind.