I'm currently using iconv
to convert documents with different encodings.
The iconv()
function has the following prototype:
size_t iconv (
iconv_t cd,
const char* * inbuf,
size_t * inbytesleft,
char* * outbuf,
size_t * outbytesleft
);
So far, I only had to convert buffers of type char*
but I also realized I could have to convert buffers of type wchar_t*
. In fact, iconv
even has a dedicated encoding name "wchar_t"
for such buffers: this encoding adapts to the operating system settings: that is, on my computers, it refers to UCS-2 on Windows and to UTF-32 on Linux.
But here lies the problem: if I have a buffer of wchar_t*
I can reinterpret_cast
it to a buffer of char*
to use it in iconv
, but then I face implementation defined behavior: I cannot be sure that the all compilers will behave the same regarding the cast.
What should I do here ?