cancel
Showing results for 
Search instead for 
Did you mean: 

Hello! I ran into the following problem In STM32cubeIDE, the sprintf function (str, "Привет"); calls encoding two characters instead of one Ascii Each even character = 208 (dec).

Mikhail Lipatov
Associate II
 
1 ACCEPTED SOLUTION

Accepted Solutions
Mikhail Lipatov
Associate II

Thanks for answers! I ADD comand gcc -fexec-charset=CP1251 in MCU GCC Compiler and its solved my problem!!

View solution in original post

3 REPLIES 3
S.Ma
Principal

Because what you input to the compiler is a unicode 16 bit string which will be converted to ASCII 8 bit character table.

208 seems to be the cyrillic page for unicode characters, mandarin will be another.

The C standard leaves the choice of character set to be implementation-defined, i.e. it depends on the compiler, how it copes with the various character sets.

In gcc, you should be able to override the default (UTF-8) encoding using the -fexec-charset switch https://gcc.gnu.org/onlinedocs/cpp/Invocation.html#index-fexec-charset (it's a preprocessor switch). You might be able to use ASCII or some of the charsets listed here.

JW

Mikhail Lipatov
Associate II

Thanks for answers! I ADD comand gcc -fexec-charset=CP1251 in MCU GCC Compiler and its solved my problem!!