How to make the following code work correctly
#include <stdio.h> #include <clocale> #include <ctype.h> int main(int argc, char** argv) { setlocale(LC_ALL, "Russian"); isupper('П'); return 0; } The problem is that in Release it falls, and in Debug it produces ASSERT: Expression: c> = -1 && c <= 255.
I have several solutions, but all do not fit in one degree or another:
- I cannot switch to UNICODE, because supported project with a large amount of such code.
- You can use the overloaded isupper function, which takes the second argument locale. I can not for the same reason - I do not want to rewrite calls everywhere.
- Surprisingly, the version works with isupper ((unsinged char) 'P'). That is, after all, RTL understands setlocale and works with Russian letters. (This is confirmed by the fact that if you remove setlocale, it will compile, but the isupper will return incorrect results.) But ASSERT does not understand this and it works regardless of locale, which is understandable, but bad.
- The option similar to (3) to put the compilation key / J (Make char as unsigned char) does not fit is incompatible with libraries, for example MFC.
- Writing your own isupper_rus functions and exchanging them with definitions is a bad way to rewrite RTL.
Question: Is it possible to solve the problem without significant rewriting of the code proposed above? So is it possible to make isupper work exactly?
TCHAReverywhere. It would have been easier with him.) - VladD