vs的char和signed char不是一个类型

C++语言 码拜 8年前 (2016-04-06) 1518次浏览
如题,vs种char和signed char和unsigned char是三种类型
那g++是怎么定义的
微软或c++标准有对这做出说明吗
那wchar_t呢?
个人觉得还不如把增加个char8_t
用于区别本机字符串,utf8字符串和BYTE
解决方案

10

char究竟是带符号的还是不带符号的是implementation defined。而且协议上char专门用来当字符,signed char和unsigned char拿来当数用。
wchar_t char16_t char32_t纯拿来当字符用的。
于是char就是你那个char8_t

10

C++ 标准明确规定这是三个类型,在说明基础类型 [3.9.1 Fundamental types] 时就是从char 开始的

20

Character types
signed char – type for signed character representation.
unsigned char – type for unsigned character representation. Also used to inspect object representations (raw memory).
char – type for character representation which can be most efficiently processed on the target system (has the same representation and alignment as either signed char or unsigned char, but is always a distinct type). Multibyte characters strings use this type to represent code units. The character types are large enough to represent 256 different values (in order to be suitable for storing UTF-8 encoded data) (since C++14)
wchar_t – type for wide character representation (see wide strings). Required to be large enough to represent any supported character code unit (32 bits on systems that support Unicode. A notable exception is Windows, where wchar_t i
http://en.cppreference.com/w/cpp/language/types

10

gcc命令行节选:
-fsigned-char           Make “char” be signed by default
-funsigned-char         Make “char” be unsigned by default

CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明vs的char和signed char不是一个类型
喜欢 (0)
[1034331897@qq.com]
分享 (0)