[haiku-development] Re: Aw: Re: Source-level incompatibility in iconv.h

  • From: Oliver Tappe <zooey@xxxxxxxxxxxxxxx>
  • To: haiku-development@xxxxxxxxxxxxx
  • Date: Tue, 28 Oct 2008 13:43:50 +0100

On 2008-10-28 at 12:19:47 [+0100], Marcus Overhagen <marcusoverhagen@xxxxxxxx> 
> Oliver Tappe wrote:
> > Yep, and that actually makes it even worse, since I bet there are several
> > applications out there which use const_cast to invoke iconv() - if we would 
> > add
> > const to our declaration, those applications could not be compiled on haiku.
> That is wrong. You can pass a non-const pointer when the function expects
> a const pointer without any problem.

I thought so, too, but have just learnt otherwise ...

Just take this little program:

------- 8< --------
#include <iconv.h>

int main()
        char* src = "täxt";
        size_t srclen = strlen(src) + 1;
        size_t destlen = 32;
        char buf[destlen];
        char* dest = buf;
        iconv_t icstate = iconv_open("iso8859-1", "utf-8");

        iconv(icstate, &src, &srclen, &dest, &destlen);
        printf("%s\n", buf);
        return 0;
------- 8< --------

Compiling it as C gives as warning:

/boot/home/Sources/temp/iconv/test1.c: In function `main':
/boot/home/Sources/temp/iconv/test1.c:12: warning: passing arg 2 of `libiconv' 
from incompatible pointer type

And in C++-mode, the compiler chokes:

/boot/home/Sources/temp/iconv/test1.c: In function `int main()':
/boot/home/Sources/temp/iconv/test1.c:12: passing `char **' as argument 2 of 
`libiconv(void *, const char **, size_t *, char **, size_t *)' adds cv-quals 
without intervening `const'

These tests have been done on R5, using a libiconv header that declares iconv() 
like this:
size_t iconv (iconv_t cd, const char* * inbuf, size_t *inbytesleft, char* * 
outbuf, size_t *outbytesleft);

So, unless I miss something, my original idea of changing haiku's iconv() 
declaration is a bad one - as it could trigger problems for other programs, at 
least in C++ mode.


Other related posts: