Microsoft C++ implementation of std::mbstate_t


I have some legacy code that works with UTF8/16 conversions and wstream-s. It has been written on VS08-VS10 and it assumes that mbstate_t's type is int. It uses it to check on some states like

while(_State & 0x80000000 && ...)


unsigned n = _State & 0x7FFFFFFF; 

But now I need to compile it with modern Visual studio, and there mbstate is presented as a struct:

typedef struct _Mbstatet
{ // state of a multibyte translation
    unsigned long _Wchar;
    unsigned short _Byte, _State;
} _Mbstatet;

I can guess that in need to use _State field in all provided above operations. But it is just 16 bit whereas in my legacy it's used with 32bit constants. I am trying to find some documentation about it, but I've not got success yet. Have someone experienced with that?

asked on Stack Overflow Apr 8, 2020 by Bogdan

1 Answer


Finally, I figured out that it's a bad idea to have assumptions on internal implementations. So, I used #if _MSC_VER >= 1925
for my code + an answer from here: Reading UTF-8 text and converting to UTF-16 using standard C++ wifstream

answered on Stack Overflow Apr 8, 2020 by Bogdan

User contributions licensed under CC BY-SA 3.0