[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: libgettext.h (Re: Documentation of ngettext)
From: |
Bruno Haible |
Subject: |
Re: libgettext.h (Re: Documentation of ngettext) |
Date: |
Thu, 13 Dec 2001 15:11:13 +0100 (CET) |
Alexandre Duret-Lutz writes:
> What I was trying to say in the previous message is that because
> the return type of gettext() and ngettext() ought to be `const
> char*' (even if it's not actually the case), people ought to
> treat it as so and write:
>
> const char *s = gettext("foobar");
> or
> const char *s = ngettext("sing","plural",n);
Agreed,
> ~/tmp % gcc -Wwrite-strings -Wcast-qual -c f.c
-Wcast-qual is a stupid warning: it warns for valid uses of built-in
C language features. It's only use is for C to C++ conversions. So
let's avoid it. Just plain -Wall is much better.
$ gcc -Wall -c f.c
gives no warning.
$ gcc -Wall -Wwrite-strings -c f.c
f.c: In function `foo':
f.c:7: warning: initialization discards qualifiers from pointer target type
You want a warning for lines 7 and 8 but not for line 9 and 10? We get
it like this, even without -Wwrite-strings:
1 # define gettext(Msgid) (const char *) (Msgid)
2 # define ngettext(Msgid1, Msgid2, N) \
3 ((N) == 1 ? (const char *) (Msgid1) : (const char *) (Msgid2))
4
5 void foo(void)
6 {
7 char* s1 = gettext("foobar");
8 char* s2 = ngettext("sing","plural", 0);
9 const char* c1 = gettext("foobar");
10 const char* c2 = ngettext("sing","plural", 0);
11
12 (void)s1, (void)s2, (void)c1, (void)c2;
13 }
> If, as suggested, you remove those casts, the annoying warning
> disappear and the usefull warnings remain:
I'll better leave the casts to 'const char *' in; they also provide
useful warnings for
char *s;
void foo(void)
{
char* s1 = gettext(s);
char* s2 = ngettext(s,s, 0);
const char* c1 = gettext(s);
const char* c2 = ngettext(s,s, 0);
}
Bruno