C++ 中的标量类型 additionnal
The scalar type additionnal in C++
在 C 中,标量类型是:
- floating_point(双浮点数,...)
- 整数(整型、字符型、长整型、...)
- 指针
- 枚举
在 C++ 中,添加的标量类型只是:
- 积分(布尔)
- nullprt_t
- 成员指针(成员对象指针和成员函数指针)
C++ 中只增加了三类标量吗?
在 C++ 中,标量类型是(6.7 类型)
9 Arithmetic types (6.7.1), enumeration types, pointer types,
pointer-to-member types (6.7.2), std::nullptr_t, and cv-qualified
(6.7.3) versions of these types are collectively called scalar types.
在 C 中,标量类型是(6.2.5 类型)
21 Arithmetic types and pointer types are collectively called scalar
types.
注意C
11 There are three complex types, designated as float _Complex, double
_Complex, and long double _Complex. 43) (Complex types are a conditional feature
that implementations need not support; see
6.10.8.3.) The real floating and complex types are collectively called the
floating types
在 C++ 中,复杂类型是用户定义的类型,它们被定义为 类。
同样在 C 中枚举属于算术类型范畴,而在 C++ 中枚举不属于算术类型范畴。
并且在 C 中有标准的无符号整数类型 _Bool
而在 C++ 中则没有。另一方面,在 C++ 中有整数类型 bool
,而 C 中没有。
根据标准(引用最新草案)的 C++ 标量类型的完整列表:
[basic.fundamental]
There are five standard signed integer types : “signed char”, “short int”, “int”, “long int”, and “long long int”
For each of the standard signed integer types, there exists a corresponding (but different) standard unsigned integer type
Types bool, char, wchar_t, char8_t, char16_t, char32_t, and the signed and unsigned integer types are collectively called integral types
There are three floating-point types: float, double, and long double.
Integral and floating-point types are collectively called arithmetic types.
[basic.compound]
pointers to non-static class members, which identify members of a given type within objects of a given class, [dcl.mptr]. Pointers to data members and pointers to member functions are collectively called pointer-to-member types.
The type of a pointer to cv void or a pointer to an object type is called an object pointer type. The type of a pointer that can designate a function is called a function pointer type.
[dcl.enum]
The enumeration type declared with an enum-key of only enum is an unscoped enumeration, and its enumerators are unscoped enumerators.
The enum-keys enum class and enum struct are semantically equivalent; an enumeration type declared with one of these is a scoped enumeration, and its enumerators are scoped enumerators.
[basic.types]
Arithmetic types ([basic.fundamental]), enumeration types, pointer types, pointer-to-member types ([basic.compound]), std::nullptr_t, and cv-qualified versions of these types are collectively called scalar types.
在这些类型中,C 缺少作用域枚举、指向成员的指针、std::nullptr_t
和 char8_t
(char8_t
尚未在 C++ 中也可以;它将在即将到来的 C++20 中引入)。
bool
(<stdbool.h>
)、wchar_t
(<stddef.h>
)、char16_t
和 char32_t
(<uchar.h>
) 类型仅在 C 的某些标准头文件中定义。
在 C 中,标量类型是:
- floating_point(双浮点数,...)
- 整数(整型、字符型、长整型、...)
- 指针
- 枚举
在 C++ 中,添加的标量类型只是:
- 积分(布尔)
- nullprt_t
- 成员指针(成员对象指针和成员函数指针)
C++ 中只增加了三类标量吗?
在 C++ 中,标量类型是(6.7 类型)
9 Arithmetic types (6.7.1), enumeration types, pointer types, pointer-to-member types (6.7.2), std::nullptr_t, and cv-qualified (6.7.3) versions of these types are collectively called scalar types.
在 C 中,标量类型是(6.2.5 类型)
21 Arithmetic types and pointer types are collectively called scalar types.
注意C
11 There are three complex types, designated as float _Complex, double _Complex, and long double _Complex. 43) (Complex types are a conditional feature that implementations need not support; see 6.10.8.3.) The real floating and complex types are collectively called the floating types
在 C++ 中,复杂类型是用户定义的类型,它们被定义为 类。
同样在 C 中枚举属于算术类型范畴,而在 C++ 中枚举不属于算术类型范畴。
并且在 C 中有标准的无符号整数类型 _Bool
而在 C++ 中则没有。另一方面,在 C++ 中有整数类型 bool
,而 C 中没有。
根据标准(引用最新草案)的 C++ 标量类型的完整列表:
[basic.fundamental]
There are five standard signed integer types : “signed char”, “short int”, “int”, “long int”, and “long long int”
For each of the standard signed integer types, there exists a corresponding (but different) standard unsigned integer type
Types bool, char, wchar_t, char8_t, char16_t, char32_t, and the signed and unsigned integer types are collectively called integral types
There are three floating-point types: float, double, and long double.
Integral and floating-point types are collectively called arithmetic types.
[basic.compound]
pointers to non-static class members, which identify members of a given type within objects of a given class, [dcl.mptr]. Pointers to data members and pointers to member functions are collectively called pointer-to-member types.
The type of a pointer to cv void or a pointer to an object type is called an object pointer type. The type of a pointer that can designate a function is called a function pointer type.
[dcl.enum]
The enumeration type declared with an enum-key of only enum is an unscoped enumeration, and its enumerators are unscoped enumerators. The enum-keys enum class and enum struct are semantically equivalent; an enumeration type declared with one of these is a scoped enumeration, and its enumerators are scoped enumerators.
[basic.types]
Arithmetic types ([basic.fundamental]), enumeration types, pointer types, pointer-to-member types ([basic.compound]), std::nullptr_t, and cv-qualified versions of these types are collectively called scalar types.
在这些类型中,C 缺少作用域枚举、指向成员的指针、std::nullptr_t
和 char8_t
(char8_t
尚未在 C++ 中也可以;它将在即将到来的 C++20 中引入)。
bool
(<stdbool.h>
)、wchar_t
(<stddef.h>
)、char16_t
和 char32_t
(<uchar.h>
) 类型仅在 C 的某些标准头文件中定义。