Date: Wed, 16 Jun 2010 22:07:58 +0200 From: =?utf-8?Q?Dag-Erling_Sm=C3=B8rgrav?= <des@des.no> To: Jaakko Heinonen <jh@FreeBSD.org> Cc: FreeBSD Current <freebsd-current@freebsd.org>, Xin LI <d@delphij.net>, Gabor Kovesdan <gabor@FreeBSD.org>, i18n@FreeBSD.org Subject: Re: [CFT] BSDL iconv in base system Message-ID: <86bpba7nc1.fsf@ds4.des.no> In-Reply-To: <20100616190416.GA3896@a91-153-117-195.elisa-laajakaista.fi> (Jaakko Heinonen's message of "Wed, 16 Jun 2010 22:04:16 %2B0300") References: <4C16C5B5.1070308@FreeBSD.org> <20100616190416.GA3896@a91-153-117-195.elisa-laajakaista.fi>
next in thread | previous in thread | raw e-mail | index | archive | help
Jaakko Heinonen <jh@FreeBSD.org> writes: > iconv(3) prototype doesn't conform to POSIX.1-2008. Is it a > well-considered decision? Probably not, because it breaks the interface. Imagine that inbuf were just a char *, not a char **. It would be perfectly safe to change it to const char *, because you can always assign a char * to a const char *. However, inbuf is a char **, which is a pointer to a pointer to char. Gabor changed it to const char **, which is a pointer to a pointer to const char. Unfortunately, the two types are incompatible. If foo is a char *, you can't pass &foo as inbuf. % cat >/tmp/const.c <<EOF #include <stdio.h> void fs(char *s) { puts(++s); } void gs(const char *s) { puts(++s); } void fsp(char **sp) { puts(++*sp); } void gsp(const char **sp) { puts(++*sp); } int main() { char *s =3D "xyzzy", **sp =3D &s; fs(s); gs(s); fsp(sp); gsp(s= p); } EOF % cc -Wall -Wextra -Werror -std=3Dc99 -o/dev/null /tmp/const.c cc1: warnings being treated as errors /tmp/const.c: In function =E2=80=98main=E2=80=99: /tmp/const.c:6: error: passing argument 1 of =E2=80=98gsp=E2=80=99 from inc= ompatible pointer type /tmp/const.c:5: note: expected =E2=80=98const char **=E2=80=99 but argument= is of type =E2=80=98char **=E2=80=99 This means you can't, say, read data from a file into a buffer and then pass that buffer to iconv, because the buffer is not const (otherwise you couldn't have read data into it). That seems like a pretty fundamental flaw. DES --=20 Dag-Erling Sm=C3=B8rgrav - des@des.no
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?86bpba7nc1.fsf>