[cpp]c++中的 _t 类的数据类型
文章目录
- 1. 简介
- 2.例子
- 3.Reference
1. 简介
_t 类的数据结构大都是用 typedef 来定义的,主要用于跨平台时,平台字长不一,会造成代码不好维护的情况。
2.例子
一般整型对应的 *_t 类型有:
- unit8_t – 1 byte
- unit16_t – 2 byte
- unit32_t – 4 byte
- unit64_t – 8 byte
下面是一个与 c99标准中的一个 int_types.h 相类似的定义文件:
bash-3.00$ vi int_types.h
"int_types.h" [Read only] 176 lines, 4367 characters
/** Copyright 2004 Sun Microsystems, Inc. All rights reserved.* Use is subject to license terms.*/#ifndef _SYS_INT_TYPES_H
#define _SYS_INT_TYPES_H#pragma ident "@(#)int_types.h 1.10 04/09/28 SMI"/** This file, <sys/int_types.h>, is part of the Sun Microsystems implementation* of <inttypes.h> defined in the ISO C standard, ISO/IEC 9899:1999* Programming language - C.** Programs/Modules should not directly include this file. Access to the* types defined in this file should be through the inclusion of one of the* following files:** <sys/types.h> Provides only the "_t" types defined in this* file which is a subset of the contents of* <inttypes.h>. (This can be appropriate for* all programs/modules except those claiming* ANSI-C conformance.)** <sys/inttypes.h> Provides the Kernel and Driver appropriate* components of <inttypes.h>.** <inttypes.h> For use by applications.** See these files for more details.*/#include <sys/feature_tests.h>#ifdef __cplusplus
extern "C" {#endif/** Basic / Extended integer types** The following defines the basic fixed-size integer types.** Implementations are free to typedef them to Standard C integer types or* extensions that they support. If an implementation does not support one* of the particular integer data types below, then it should not define the* typedefs and macros corresponding to that data type. Note that int8_t* is not defined in -Xs mode on ISAs for which the ABI specifies "char"* as an unsigned entity because there is no way to define an eight bit* signed integral.*/
#if defined(_CHAR_IS_SIGNED)
typedef char int8_t;
#else
#if defined(__STDC__)
typedef signed char int8_t;
#endif
#endif
typedef short int16_t;
typedef int int32_t;
#ifdef _LP64
#define _INT64_TYPE
typedef long int64_t;
#else /* _ILP32 */
#if defined(_LONGLONG_TYPE)
#define _INT64_TYPE
typedef long long int64_t;
#endif
#endiftypedef unsigned char uint8_t;
typedef unsigned short uint16_t;
typedef unsigned int uint32_t;
#ifdef _LP64
typedef unsigned long uint64_t;
#else /* _ILP32 */
#if defined(_LONGLONG_TYPE)
typedef unsigned long long uint64_t;
#endif
#endif/** intmax_t and uintmax_t are to be the longest (in number of bits) signed* and unsigned integer types supported by the implementation.*/
#if defined(_INT64_TYPE)
typedef int64_t intmax_t;
typedef uint64_t uintmax_t;
#else
typedef int32_t intmax_t;
typedef uint32_t uintmax_t;
#endif/** intptr_t and uintptr_t are signed and unsigned integer types large enough* to hold any data pointer; that is, data pointers can be assigned into or* from these integer types without losing precision.*/
#if defined(_LP64) || defined(_I32LPx)
typedef long intptr_t;
typedef unsigned long uintptr_t;
#else
typedef int intptr_t;
typedef unsigned int uintptr_t;
#endif/** The following define the fastest integer types that can hold the* specified number of bits.*/
#if defined(_CHAR_IS_SIGNED)
typedef char int_fast8_t;
#else
#if defined(__STDC__)
typedef signed char int_fast8_t;
#endif
#endif
typedef int int_fast16_t;
typedef int int_fast32_t;
#ifdef _LP64
typedef long int_fast64_t;
#else /* _ILP32 */
#if defined(_LONGLONG_TYPE)
typedef long long int_fast64_t;
#endif
#endiftypedef unsigned char uint_fast8_t;
typedef unsigned int uint_fast16_t;
typedef unsigned int uint_fast32_t;
#ifdef _LP64
typedef unsigned long uint_fast64_t;
#else /* _ILP32 */
#if defined(_LONGLONG_TYPE)
typedef unsigned long long uint_fast64_t;
#endif
#endif/** The following define the smallest integer types that can hold the* specified number of bits.*/
#if defined(_CHAR_IS_SIGNED)
typedef char int_least8_t;
#else
#if defined(__STDC__)
typedef signed char int_least8_t;
#endif
#endif
typedef short int_least16_t;
typedef int int_least32_t;
#ifdef _LP64
typedef long int_least64_t;
#else /* _ILP32 */
#if defined(_LONGLONG_TYPE)
typedef long long int_least64_t;
#endif
#endiftypedef unsigned char uint_least8_t;
typedef unsigned short uint_least16_t;
typedef unsigned int uint_least32_t;
#ifdef _LP64
typedef unsigned long uint_least64_t;
#else /* _ILP32 */
#if defined(_LONGLONG_TYPE)
typedef unsigned long long uint_least64_t;
#endif
#endif#ifdef __cplusplus
}
#endif#endif /* _SYS_INT_TYPES_H */
3.Reference
- c/c++: uint8_t uint16_t uint32_t uint64_t size_t ssize_t数据类型 csdn
[cpp]c++中的 _t 类的数据类型相关推荐
- boost::regex模块在 cpp 文件中搜索类定义,使用全局数据的测试程序
boost::regex模块在 cpp 文件中搜索类定义,使用全局数据的测试程序 实现功能 C++实现代码 实现功能 boost::regex模块在 cpp 文件中搜索类定义,使用全局数据的测试程序 ...
- boost::regex模块在 cpp 文件中搜索类定义,使用 C++ Builder 闭包作为回调的测试程序
boost::regex模块在 cpp 文件中搜索类定义,使用 C++ Builder 闭包作为回调的测试程序 实现功能 C++实现代码 实现功能 boost::regex模块在 cpp 文件中搜索类 ...
- boost::regex模块在 cpp 文件中搜索类定义,使用绑定成员函数回调测试程序
boost::regex模块在 cpp 文件中搜索类定义,使用绑定成员函数回调测试程序 实现功能 C++实现代码 实现功能 boost::regex模块在 cpp 文件中搜索类定义,使用绑定成员函数回 ...
- boost::regex模块在 cpp 文件中搜索类定义,使用全局回调函数的测试程序
boost::regex模块在 cpp 文件中搜索类定义,使用全局回调函数的测试程序 实现功能 C++实现代码 实现功能 boost::regex模块在 cpp 文件中搜索类定义,使用全局回调函数的测 ...
- boost::regex模块实现在 cpp 文件中搜索类定义的测试程序
boost::regex模块实现在 cpp 文件中搜索类定义的测试程序 实现功能 C++实现代码 实现功能 boost::regex模块实现在 cpp 文件中搜索类定义的测试程序 C++实现代码 #i ...
- 将类的定义放在头文件中,把成员函数的实现代码放在一个cpp文件中
将类的定义放在头文件中,把成员函数的实现代码放在一个cpp文件中 写这种.h和.cpp文件分开的大程序,虽然对很多人来说很简单,对自己来说算是第一次吧,好好学C++,加油~ 题目:定义Point类,由 ...
- java中的POJO类属性建议使用包装数据类型
1.说明 POJO 类属性没有初值是提醒使用者在需要使用时,必须自己显式地进行赋值,任何NPE(NullPointerException,空指针异常) 问题,或者入库检查,都由使用者来保证. 2.举例 ...
- C++ 中的模板类声明头文件和实现文件分离后,如何能实现正常编译?
著作权归作者所有. 商业转载请联系作者获得授权,非商业转载请注明出处. 作者:余天升 链接:http://www.zhihu.com/question/20630104/answer/15722407 ...
- MFC中的CAsyncSocket类实现网络通信
近年来,利用Internet进行网际间通讯,在WWW浏 览.FTP.Gopher这些常规服务,以及在网络电话.多媒体会议等这些对实时性要求严格 的应用中成为研究的热点,而且已经是必需的了.Window ...
最新文章
- ads无法启用状态服务器,NAC ADSSO 无法工作在Microsoft 2008服务器版本
- C语言再学习 -- 位操作
- Apollo灰度发布
- 智能家居火了这么久 何时到我家?
- Javascript的枚举属性
- ESP8266热点配网-Arduino代码分享
- Premiere使用教程(一)新建项目和序列
- 浅谈NB-IOT模块调试
- FreeIPA 4.7.0 服务端 部署
- CleanMyMac X苹果电脑系统管家级的多功能百宝箱
- 林中鸟计算机弹奏,用现象证实现象这叫复试,计算机的计算只是计算,与经络的现象无关。气感循行...
- java 中介模式_中介者模式
- 响铃:“头号玩家”乐车邦,恰恰踩到了“无人”的点上
- 期许2016 迎新春技术分享沙龙总结
- 2019 siggraph_观看SIGGRAPH 2019的Unity图形会议
- python读取excel文本单元格换行符_Excel自文本导入内容时如何做到单元格内换行...
- CUDA_NVCC_FLAGS set
- 网络基础——牛客网刷题第一波
- 向sdcard中添加文件为什么总是提示Failed to push the item(s)Failed to push XXXXX.txt on emulato...
- 进入51.com个人主页