Fundamental types
Fundamental types
- void type
- boolean type
- character types
- integer types
- Properties
- Data Models
- Floating-point types
- Floating-point properties
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)signed
or unsigned
和short
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 Specifier | Equivalent Type | C++Standard | LP32 | ILP32 | LLP64 | LP64 |
---|---|---|---|---|---|---|
short |
short int |
at least 16 | 16 | 16 | 16 |
16 |
short int |
short int |
at least 16 | 16 | 16 | 16 |
16 |
signed int |
short int |
at least 16 | 16 | 16 | 16 |
16 |
signed short int |
short int |
at least 16 | 16 | 16 | 16 |
16 |
unsigned short |
unsigned short int |
at least 16 | 16 | 16 | 16 |
16 |
unsigned short int |
unsigned short int |
at least 16 | 16 | 16 | 16 |
16 |
int |
int |
at least 16 | 16 | 32 | 32 |
32 |
signed |
int |
at least 16 | 16 | 32 | 32 |
32 |
signed int |
int |
at least 16 | 16 | 32 | 32 |
32 |
unsigned |
unsigned int |
at least 16 | 16 | 32 | 32 |
32 |
unsigned int |
unsigned int |
at least 16 | 16 | 32 | 32 |
32 |
long |
long int |
at least 32 | 32 | 32 | 32 |
64 |
signed long |
long int |
at least 32 | 32 | 32 | 32 |
64 |
signed long int |
long int |
at least 32 | 32 | 32 | 32 |
64 |
unsigned long |
unsigned long int |
at least 32 | 32 | 32 | 32 |
64 |
unsigned long int |
unsigned long int |
at least 32 | 32 | 32 | 32 |
64 |
long long |
long long int |
at least 32 | 64 | 64 | 64 |
64 |
long long int |
long long int |
at least 32 | 64 | 64 | 64 |
64 |
signed long long |
long long int |
at least 32 | 64 | 64 | 64 |
64 |
signed long long int |
long long int |
at least 32 | 64 | 64 | 64 |
64 |
unsigned long long |
long long int |
at least 32 | 64 | 64 | 64 |
64 |
unsigned long long |
unsigned long long int since C++11 |
at least 32 | 64 | 64 | 64 |
64 |
unsigned long long int |
unsigned long long int since C++11 |
at least 32 | 64 | 64 | 64 |
64 |
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 particularinteger 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:
- Win16API
- LLP64 or 4/4/8 (
int
andlong
are 32-bit,pointer
is 64-bit)- Win64 API
- LP64 or 4/8/8 (
int
is 32-bit,long
andpointer
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 architecturesFloating-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
, but1.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
Fundamental types的更多相关文章
- The main difference between Java & C++(转载)
转载自:http://stackoverflow.com/questions/9192309/the-main-difference-between-java-c C++ supports point ...
- Java Main Differences between Java and C++
转载自:http://www.cnblogs.com/springfor/p/4036739.html C++ supports pointers whereas Java does not. But ...
- char, signed char, and unsigned char in C++
关于这三者的区别stackoverrflow里有一个答案是这样说的: 3.9.1 Fundamental types [basic.fundamental] 1 Objects declared as ...
- Java中接口作为方法的返回
在<算法>中的散列表一节,在用拉链法实现散列表的API时要求实现以下一个方法: public Iterable<Key> keys() 我们知道Iterable是一个接口,那么 ...
- C++ Bit Fields
http://msdn.microsoft.com/en-us/library/ewwyfdbe%28v=vs.71%29.aspx Note An unnamed bit field of widt ...
- Open CASCADE 基础类(Foundation Classes)
1 介绍(Introduction) 1 如何使用Open CASCADE技术(OCCT)基础类. This manual explains how to use Open CASCADE Techn ...
- 《Velocity java开发指南》中文版(上)转载
文章引自:http://sakyone.iteye.com/blog/524289 1.开始入门 Velocity是一基于java语言的模板引擎,使用这个简单.功能强大的开发工具,可以很容易的将数据对 ...
- (转) class II
Overloading operators Classes, essentially, define new types to be used in C++ code. And types in ...
- (转) Class
Classes are an expanded concept of data structures: like data structures, they can contain data memb ...
随机推荐
- BZOJ 1044: [HAOI2008]木棍分割(二分答案 + dp)
第一问可以二分答案,然后贪心来判断. 第二问dp, dp[i][j] = sigma(dp[k][j - 1]) (1 <= k <i, sum[i] - sum[k] <= ans ...
- 5.6.3.4 trim()方法
ECMAScript 5 为所有字符串定义了trim()方法.这个方法会创建一个字符串的副本,删除前置以及后缀的所有空格,然后返回结果.例如: var stringValue = " hel ...
- Oracle分区知识
查询分区名称.表空间的SQL USER_SEGMENTS SELECT SEGMENT_NAME,PARTITION_NAME,TABLESPACE_NAME FROM USER_SEGMENTS; ...
- Android UiAutomator 自动化测试一些代码实例---新手3
1.打开浏览器,打开百度实例 public void testBrowser() throws RemoteException, UiObjectNotFoundException{ //灭屏幕-亮屏 ...
- struts2上传下载
struts上传下载必须引入两个jar文件: commons-fileupload-x.x.x.jar和comons-io-x.x.x.jar上传文件 import java.io.BufferedI ...
- js+jquery+css3
(原生js+jquery+css3) 前言 项目需求要弄个瀑布流的页面,用的是waterfall这个插件,感觉还是可以的,项目赶就没自己的动手写.最近闲来没事,就自己写个.大致思路理清楚,还是挺好实现 ...
- 帝国cms本地搬家到服务器文章路径问题?
由于我的服务器不支持采集功能,我只能选择先在本地采集好文章发布于本地,再打算同步于服务器. 按照官方的做法, 1.先进后台备份了网站的所有数据,系统——备份与恢复数据——备份数据 2.将e\admin ...
- 射频识别技术漫谈(15)——Mifare1的安全性及7字节序列号M1卡
Mifare1的安全性主要指卡中数据的安全性,要求卡中的数据不能被非法修改或窃听.数据的安全性主要使用加密技术来保证,加密技术有两个关键因素:加密算法和密钥.现代加密技术的一大特点是加密算法公开,如果 ...
- uva 10651 - Pebble Solitaire(记忆化搜索)
题目链接:10651 - Pebble Solitaire 题目大意:给出一个12格的棋盘,‘o'代表摆放棋子,’-‘代表没有棋子, 当满足’-oo'时, 最右边的棋子可以跳到最左边的位子,而中间的棋 ...
- SVN同步出现故障
1.错误描写叙述 同步SVNStatusSubscribe时报告了错误,1中的0个资源已经同步 同步/frame时错误发生:Error getting status for resourc ...