iconv: more pain


Subject: iconv: more pain
From: David Mandelin (mandelin@cs.wisc.edu)
Date: Mon Aug 20 2001 - 13:20:03 CDT


Dom Lachowicz wrote:
>
> 1) I've made my proposed change to UT_iconv which should handle the const_cast
> properly on all compilers and iconv implementations. Should be fixed now, but if
> this breaks for anyone, please tell me

It breaks MSVC 6 and gcc2.95.3-5. On MSVC, "ut_iconv.cpp(143) : error
C2664: 'iconv' : cannot convert parameter 2 from 'char ** ' to 'const
char ** ' Conversion loses qualifiers". On gcc, "initialization to
`const char **' from `char **' adds cv-quals without intervening
`const'".

Converting 'char **' to 'const char **' implicitly is not allowed by the
standard (as found at
http://www.csci.csusb.edu/dick/c++std/cd2/index.html). (You can convert
'char **' to 'const char * const *', which is why gcc mentions
'intervening const'.)

I have absolutely no idea how to fix this without some new #defines.

By the way, what is up with gcc 3.0? The standard says "Any expression
may be cast to its own type using a const_cast operator." Maybe it's a
bug.

size_t UT_iconv( UT_iconv_t cd, const char **inbuf,
                  size_t *inbytesleft, char **outbuf, size_t *outbytesleft )
{
    // this should take care of iconv problems with different compilers,
    // esp. strict ones like gcc3.0, and the other older iconv
prototypes
    char ** buf = const_cast<char **>(inbuf);
    return iconv( cd, buf, inbytesleft, outbuf, outbytesleft );
}



This archive was generated by hypermail 2b25 : Mon Aug 20 2001 - 13:20:10 CDT