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: "Michael Kerrisk (man-pages)" <mtk dot manpages at gmail dot com>
- To: Andreas Schwab <schwab at suse dot de>
- Cc: "libc-alpha at sourceware dot org" <libc-alpha at sourceware dot org>, Igor Liferenko <igor dot liferenko at gmail dot com>
- Date: Mon, 21 Nov 2016 13:54:48 +0100
- Subject: Re: Signedness of wchar_t and wint_t leads to problems with gcc -Wsign-conversion
- Authentication-results: sourceware.org; auth=none
- References: <CAKgNAkhjsE=OpLj=S9btNBQVj-OAr7Fd3y6RDp4M7SFkoPGHbg@mail.gmail.com> <mvm8tsd0zoq.fsf@hawking.suse.de>
- Reply-to: mtk dot manpages at gmail dot com
Hello Andreas,
On 21 November 2016 at 13:45, Andreas Schwab <schwab@suse.de> wrote:
> On Nov 21 2016, "Michael Kerrisk (man-pages)" <mtk.manpages@gmail.com> wrote:
>
>> However, we don't have a similar solution for iswlower(), because
>> there is no "(unsigned wchar_t)" cast. And casting to (wint_t) seems
>> incorrect to me, because if wchar_t is a signed type smaller than
>> wint_t, then sign extension could occur.
>
> wint_t is "an integer type capable of storing any valid value of wchar_t
> or WEOF".
Yes.
> If the sign-extended value of a wchar_t isn't a valid value
> then you have undefined behaviour.
See below.
> WEOF must be defined such that no
> conflict can occur with any valid wchar_t value.
Yes.
So, I'm not quite clear on the point that you are making in your
second point. Given code such as:
wchar_t w;
...
if (iswlower((wint_t) w) ....
Do you mean that the standards are saying that casting to wint_t here
is guaranteed to be correct? I can't see the line of reasoning that
leads there.
Cheers,
Michael
--
Michael Kerrisk
Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/
Linux/UNIX System Programming Training: http://man7.org/training/