Signedness of wchar_t and wint_t leads to problems with gcc -Wsign-conversion

Michael Kerrisk (man-pages) mtk.manpages@gmail.com
Mon Nov 21 12:55:00 GMT 2016


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/



More information about the Libc-alpha mailing list