This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: Signedness of wchar_t and wint_t leads to problems with gcc -Wsign-conversion
- From: Szabolcs Nagy <szabolcs dot nagy at arm dot com>
- To: Igor Liferenko <igor dot liferenko at gmail dot com>, <libc-alpha at sourceware dot org>
- Cc: <nd at arm dot com>, <schwab at suse dot de>, <mtk dot manpages at gmail dot com>, <zackw at panix dot com>
- Date: Wed, 23 Nov 2016 11:57:11 +0000
- Subject: Re: Signedness of wchar_t and wint_t leads to problems with gcc -Wsign-conversion
- Authentication-results: sourceware.org; auth=none
- Authentication-results: spf=none (sender IP is ) smtp.mailfrom=Szabolcs dot Nagy at arm dot com;
- Nodisclaimer: True
- References: <CAKgNAkhjsE=OpLj=S9btNBQVj-OAr7Fd3y6RDp4M7SFkoPGHbg@mail.gmail.com> <mvm8tsd0zoq.fsf@hawking.suse.de> <CAKgNAkiZWYo4TdVhXhpiPhsdYBtMOJ0PWePTA2p1BKFBaWv=Ag@mail.gmail.com> <mvm37il0yxt.fsf@hawking.suse.de> <fb703f4f-6874-8820-1502-1ae09ebb74f6@gmail.com> <mvmy40dynbu.fsf@hawking.suse.de> <2046ed8b-ad23-84a7-8ead-253a8a8a934a@gmail.com> <CAKCAbMjgLuu5pZsRFA=1e1TnUJ0O4Lh-OnA_WwX0jQdd8Mctfw@mail.gmail.com> <mvmh970zyoi.fsf@hawking.suse.de> <CAKCAbMg-BNynSUMOrxwPt2hrJkns7QkJWM10t=-xNZWCTeMV3Q@mail.gmail.com> <CAJyx362n7=ZGEk9H15M17fDgm8vjAEJPYxTCZ-QP=MibW91k2Q@mail.gmail.com>
- Spamdiagnosticmetadata: NSPM
- Spamdiagnosticoutput: 1:99
On 23/11/16 05:50, Igor Liferenko wrote:
> Can you please say if the typecasts in the following two programs are valid?
> (I just replaced wint_t and wchar_t to their actual meaning in glibc)
>
that is not valid (to replace the types) as they are
target dependent, so the code is no longer portable
and you didnt say what targets you are interested in.
> #include <locale.h>
> #include <wchar.h>
> int main(void)
> {
> setlocale(LC_CTYPE, "en_US.UTF-8");
> unsigned int wc;
> wc = getwchar();
> putwchar((int) wc);
getwchar may return WEOF, you need to check for that
before passing wc to putwchar.
if the check is performed, then the cast is unnecessary
(but valid) if the right types are used.
> }
>
> --
>
> #include <locale.h>
> #include <wchar.h>
> #include <wctype.h>
> int main(void)
> {
> setlocale(LC_CTYPE, "en_US.UTF-8");
> int wc;
> wc = L'ÿ';
> if (iswlower((unsigned int) wc)) return 0;
the cast is unnecessary, it does not change the value
(assuming the right types are used).
> return 1;
> }
>
>
> Igor
>