This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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


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
> 


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]