May wchar_t be promoted to wint_t?

2019-07-05 20:02发布

I see one contradiction of glibc reference and Amendment 1 to C90.

The quote from glibc reference says that wchar_t may be promoted to wint_t:

if wchar_t is defined as char the type wint_t must be defined as int due to the parameter promotion

But AMD1 says this:

Currently, an existing implementation could have wchar_t be int and wint_t be long, and default promotions would not change int to long. Basically, this is due to wchar_t and wint_t being typedefs. Hence, we will not now have wchar_t be promoted to wint_t.

Does anybody know which one is correct?

Are the standards saying that casting to unsigned int and to int in the following two programs is guaranteed to be correct? (I just replaced wint_t and wchar_t to their actual meaning in glibc) (I just replaced wint_t and wchar_t to their actual meaning in glibc)

#include <locale.h>
#include <wchar.h>
int main(void)
{
  setlocale(LC_CTYPE, "en_US.UTF-8");
  unsigned int wc;
  wc = getwchar();
  putwchar((int) wc);
}

--

#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;
  return 1;
}

0条回答
登录 后发表回答