I’m writing an implementation of std::codecvt facet that uses iconv. This implementation stores a pointer to heap-allocated data in std::mbstate_t state argument.
Everything works fine, but is this code 64-bit compatible?
Is there a platform where a pointer size exceeds the size of std::mbstate_t?
Doesn’t the
codecvttemplate take the state type as a parameter? Can you just use a pointer type there instead? I can’t remember whether the various classes that use acodecvtplace requirements on the state type.Assuming that you can’t just change the state type… on MSVC 2008,
mbstate_tistypedefd as anint. The standard only requires thatintbe larger than 16 bits and no larger than a long, so it’s not 64-bit safe. I guess you would need to store an index or key into some data structure instead of a pointer.update:
The following compiles under VS2008, at least: