In the document of iconv, the function synopsis is this:
#include <iconv.h>
size_t iconv (iconv_t cd, const char* * inbuf,
size_t * inbytesleft,
char* * outbuf,
size_t * outbytesleft);
But, when I check the iconv.h in my system, the function synopsis is this:
extern size_t iconv (iconv_t __cd, char **__restirct __inbuf,
size_t *__restrict __inbytesleft,
char **__restirct __outbuf,
size_t *__restrict __outbytesleft);
In these two function synopses, one is const char **, but the other one is only char **.
Why is the function synopsis in the document different from the one in my system? And why does the iconv function need a non-const inbuffer?
The version of my g++ is 6.3.0.
The problem with
iconv()is that it's not part of the C standard, but it's specified in two different standards. One of them is POSIX-1.2008:The other one is SUSv2:
They differ in
constness of**inbuf,so if you want to stay portable between both standards, you'll have to pass a non-const**inbuf, unfortunately.Edit: As this is a double pointer, the problem is even worse, see my answer here. In a nutshell, these specifications aren't compatible in either direction...
What you linked as "document of iconv" is the documentation of GNU
libiconv, which is intended to be used on platforms that don't natively provideiconv()-- this one obviously follows the SUSv2 specification.The header file you find on your system belongs to
glibc, your platform's C library, and this implementation follows the POSIX-1.2008 specification.