Fundamental types

Fundamental types

Void type

void-type with an empty set of values.There are no arrays of void,nor references to void.However,pointers to void and function returning type void are permitted.
std::nullptr_t

Boolean type

bool-type,capable of holding one of the tow values:true or false

Character types

signed char
unsigned char
char
wchar_t
char16_t
char32_t

Integer types

int - basic integer type.The keyword int may omitted if any of the modifiers listed below are used. If no length modifiers present,it's guaranteed to have a width of at least 16 bits.However,on 32/64 bit system is is almost exclusively guaranteed to have width of at least 32 bits.

Modifiers

Modifies the integer type.Can be mixed in any order. Only one of each group can be present in type name.

Signedness

signed-target type will have signed representation(this is the default if omitted)
unsigned- target type will have unsigned representation

Size

short-target type will be optimized for space and will have width of at least 16bits
long-target type will have width of at least 32 bits.

long long-target type will have width of at least 64 bits.(since C++11)

即int为integer type的基本类型,通过添加修饰符(modifiers)signedor unsignedshort or long or long long来实现存储空间位数的大小,C++保证每一个类型的最小位数

Properties

LP=Long Point
LLP=Long Long Point
The following table summarizes all available integer types and their properties:

Type SpecifierEquivalent TypeC++StandardLP32ILP32LLP64LP64
shortshort intat least 1616161616
short intshort intat least 1616161616
signed intshort intat least 1616161616
signed short intshort intat least 1616161616
unsigned shortunsigned short intat least 1616161616
unsigned short intunsigned short intat least 1616161616
intintat least 1616323232
signedintat least 1616323232
signed intintat least 1616323232
unsignedunsigned intat least 1616323232
unsigned intunsigned intat least 1616323232
longlong intat least 3232323264
signed longlong intat least 3232323264
signed long intlong intat least 3232323264
unsigned longunsigned long intat least 3232323264
unsigned long intunsigned long intat least 3232323264
long longlong long intat least 3264646464
long long intlong long intat least 3264646464
signed long longlong long intat least 3264646464
signed long long intlong long intat least 3264646464
unsigned long longlong long intat least 3264646464
unsigned long longunsigned long long int
since C++11
at least 3264646464
unsigned long long intunsigned long long int
since C++11
at least 3264646464

Besides the minimal bit counts,the C++ Standard guaranteed that
1 == sizeof(char) <= sizeof(short) <= sizeof(int) <= sizeof(long) <= sizeof(long long)

Note:integer arithmetic is defined differently for signed and unsigned integer types.See arithmetic operators,in particular integer overflows

Win64 is a LLP64 platform, while Solaris and Linux are LP64 platforms. Thus the only safe way to store pointers in integer types is either always use uintptr_t (defined in stdint.h not included at least with MSVC2003 and earlier), or always use long long fields.

Data models

The choices made by each implementation about the sizes of the fundamental types are collectively known as data model. Four data models found wide acceptance:
32 bit systems:

  • LP32 or 2/4/4 (int is 16-bit, long and pointer are 32-bit)
    • Win16API
      64 bit systems:
  • LLP64 or 4/4/8 (int and long are 32-bit, pointer is 64-bit)
    • Win64 API
  • LP64 or 4/8/8 (int is 32-bit, long and pointer are 64-bit)
    • Unix and Unix-like systems (Linux, Mac OS X)

      Floating-point types

      float- single precision floating point type.Usually IEEE-754 32 bit floating point type
      double - double precision floating point type. Usually IEEE-754 64 bit floating point type
      long double - extended precision floating point type. Does not necessarily map to types mandated by IEEE-754. Usually 80-bit x87 floating point type on x86 and x86-64 architectures

      Floating-point properties

      Floating-point types may support special values:
  • infinity (positive and negative)
  • the negative zero.-0.0.It compares equal to the positive zero, but is meaningful in some arithmetic operations, e.g. 1.0/0.0 == INFINITY, but 1.0/-0.0 == -INFINITY), and for some mathematical functions, e.g. sqrt(std::complex)
  • not-a-number (NaN), which does not compare equal with anything (including itself).

Real floating-point numbers may be used with arithmetic operators + - / * and various mathematical functions from cmath. Both built-in operators and library functions may raise floating-point exceptions and set errno as described in math_errhandling.

浮点数的精度表示FLT_EVAL_METHOD和精收缩问题#pragma STDC FP_CONTRACT
Floating-point expressions may have greater range and precision than indicated by their types, see FLT_EVAL_METHOD. Floating-point expressions may also be contracted, that is, calculated as if all intermediate values have infinite range and precision, see #pragma STDC FP_CONTRACT.

Implicit conversions are defined between real floating types and integer types.

See Limits of floating point types and std::numeric_limits for additional details, limits, and properties of the floating-point types.

Note: actual (as opposed to guaranteed minimal) limits on the values representable by these types are available in <climits>, <cfloat> and std::numeric_limits

转载于:https://www.cnblogs.com/Wojoin/p/5165742.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值