Is there a reason why the C or C ++ compiler does not define wctrans_t and wctype_t as the type wchar_t?

Actually, I am working on comparing data types between programming languages, and here is my problem when reading C and C ++ standards.

Quote from C11,

wctrans_t is a scalar type that can contain values ​​that represent language character mappings

wctype_t is a scalar type that may contain values ​​that represent language character classifications

A scalar type phrase indicates that C11 does not restrict wctrans_t and wctype_t specific scalar type.

My GCC 4.8 from MinGW implements wctrans_t and wctype_t as typedef for wchar_t , and I can't think that there is a reason why any other C compilers will not define them as they are.

Can someone prove otherwise, or provide an opportunity for this?

+5
source share
2 answers

I am surprised that someone defined them as wchar_t , neither wctype_t nor wctrans_t have anything to do with characters.

Both platforms that I use define them as something else:

 aix~$ grep wctype_t /usr/include/*h | grep typedef /usr/include/ctype.h: typedef unsigned int wctype_t; aix~$ grep wctrans_t /usr/include/*h | grep typedef /usr/include/wctype.h:typedef wint_t (*wctrans_t)(); solaris~$ grep wctype_t /usr/include/*h | grep typedef /usr/include/wchar.h:typedef int wctype_t; solaris~$ grep wctrans_t /usr/include/*/*h | grep typedef /usr/include/iso/wctype_iso.h:typedef unsigned int wctrans_t; 
+7
source

Cubby has already answered this question. Here is a couple of additional information, since the definition of the standard does not really explain itself.

A wctype_t represents a locale-specific classification character. Thus, this is not about the characters, but about their classification (for example, the old isalpha (), isalnum (), ..). The wctype_t values ​​are used by the iswctype () function to validate a wide character. Example (C11, section 7.30.2.2.1):

 iswctype(wc, wctype("alnum")) // iswalnum(wc) iswctype(wc, wctype("alpha")) // iswalpha(wc) iswctype(wc, wctype("blank")) // iswblank(wc) iswctype(wc, wctype("lower")) // iswlower(wc) ... 

Similarly, the wctrans_t view represents language bindings of characters. . Thus, this does not concern the character set, but it is a mapping from one type of wide characters to the corresponding tone (for example, like the old toupper (), lower (), ...). The mappings are described in section 7.30.3 of standard C11), here are some examples:

 towctrans(wc, wctrans("tolower")) // towlower(wc) towctrans(wc, wctrans("toupper")) // towupper(wc) 

The definition of wchar_t that you mention seems to me misleading, although wchar_t is also an integer.

Here, as defined in MSVC13:

 typedef unsigned short wint_t; typedef unsigned short wctype_t; typedef wchar_t wctrans_t; // yes, here too ! 
+4
source

Source: https://habr.com/ru/post/1200602/


All Articles