May wchar_t be promoted to wint_t?

孤者浪人 提交于 2020-01-04 02:18:25

问题


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;
}

来源:https://stackoverflow.com/questions/40757681/may-wchar-t-be-promoted-to-wint-t

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!