[CFT] BSDL iconv in base system
Dag-Erling Smørgrav
des at des.no
Wed Jun 16 20:10:10 UTC 2010
Jaakko Heinonen <jh at 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 = "xyzzy", **sp = &s; fs(s); gs(s); fsp(sp); gsp(sp); }
EOF
% cc -Wall -Wextra -Werror -std=c99 -o/dev/null /tmp/const.c
cc1: warnings being treated as errors
/tmp/const.c: In function ‘main’:
/tmp/const.c:6: error: passing argument 1 of ‘gsp’ from incompatible pointer type
/tmp/const.c:5: note: expected ‘const char **’ but argument is of type ‘char **’
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
--
Dag-Erling Smørgrav - des at des.no
More information about the freebsd-current
mailing list