C语言拾遗——inttypes.h
今天偶然间看到这个头文件inttypes,好奇有什么用,去找度娘玩了一波,发现这头文件挺有意思的。
这个头文件适配于C99标准,它提供整数输入的各种进制转换的宏,这是在Ubuntu上扣下来的代码(windows里我没找到放在哪)嗯~ o(* ̄▽ ̄*)o我拿VScode找到了……所以划掉
不完整的
Ubuntu:
//这里应该是10进制的宏
/* Decimal notation. */
# define PRId8 "d"
# define PRId16 "d"
# define PRId32 "d"
# define PRId64 __PRI64_PREFIX "d" # define PRIdLEAST8 "d"
# define PRIdLEAST16 "d"
# define PRIdLEAST32 "d"
# define PRIdLEAST64 __PRI64_PREFIX "d" # define PRIdFAST8 "d"
# define PRIdFAST16 __PRIPTR_PREFIX "d"
# define PRIdFAST32 __PRIPTR_PREFIX "d"
# define PRIdFAST64 __PRI64_PREFIX "d" # define PRIi8 "i"
# define PRIi16 "i"
# define PRIi32 "i"
# define PRIi64 __PRI64_PREFIX "i" # define PRIiLEAST8 "i"
# define PRIiLEAST16 "i"
# define PRIiLEAST32 "i"
# define PRIiLEAST64 __PRI64_PREFIX "i" # define PRIiFAST8 "i"
# define PRIiFAST16 __PRIPTR_PREFIX "i"
# define PRIiFAST32 __PRIPTR_PREFIX "i"
# define PRIiFAST64 __PRI64_PREFIX "i" //感觉这里是8进制的宏
/* Octal notation. */
# define PRIo8 "o"
# define PRIo16 "o"
# define PRIo32 "o"
# define PRIo64 __PRI64_PREFIX "o" # define PRIoLEAST8 "o"
# define PRIoLEAST16 "o"
# define PRIoLEAST32 "o"
# define PRIoLEAST64 __PRI64_PREFIX "o" # define PRIoFAST8 "o"
# define PRIoFAST16 __PRIPTR_PREFIX "o"
# define PRIoFAST32 __PRIPTR_PREFIX "o"
# define PRIoFAST64 __PRI64_PREFIX "o" //这里因该是无符号的宏
/* Unsigned integers. */
# define PRIu8 "u"
# define PRIu16 "u"
# define PRIu32 "u"
# define PRIu64 __PRI64_PREFIX "u" # define PRIuLEAST8 "u"
# define PRIuLEAST16 "u"
# define PRIuLEAST32 "u"
# define PRIuLEAST64 __PRI64_PREFIX "u" # define PRIuFAST8 "u"
# define PRIuFAST16 __PRIPTR_PREFIX "u"
# define PRIuFAST32 __PRIPTR_PREFIX "u"
# define PRIuFAST64 __PRI64_PREFIX "u" //这里因该是小写16进制
/* lowercase hexadecimal notation. */
# define PRIx8 "x"
# define PRIx16 "x"
# define PRIx32 "x"
# define PRIx64 __PRI64_PREFIX "x" # define PRIxLEAST8 "x"
# define PRIxLEAST16 "x"
# define PRIxLEAST32 "x"
# define PRIxLEAST64 __PRI64_PREFIX "x" # define PRIxFAST8 "x"
# define PRIxFAST16 __PRIPTR_PREFIX "x"
# define PRIxFAST32 __PRIPTR_PREFIX "x"
# define PRIxFAST64 __PRI64_PREFIX "x" //这里因该是大写16进制
/* UPPERCASE hexadecimal notation. */
# define PRIX8 "X"
# define PRIX16 "X"
# define PRIX32 "X"
# define PRIX64 __PRI64_PREFIX "X" # define PRIXLEAST8 "X"
# define PRIXLEAST16 "X"
# define PRIXLEAST32 "X"
# define PRIXLEAST64 __PRI64_PREFIX "X" # define PRIXFAST8 "X"
# define PRIXFAST16 __PRIPTR_PREFIX "X"
# define PRIXFAST32 __PRIPTR_PREFIX "X"
# define PRIXFAST64 __PRI64_PREFIX "X"
Windows:
/* fprintf macros for signed types */
#define PRId8 "d"
#define PRId16 "d"
#define PRId32 "d"
#define PRId64 "I64d" #define PRIdLEAST8 "d"
#define PRIdLEAST16 "d"
#define PRIdLEAST32 "d"
#define PRIdLEAST64 "I64d" #define PRIdFAST8 "d"
#define PRIdFAST16 "d"
#define PRIdFAST32 "d"
#define PRIdFAST64 "I64d" #define PRIdMAX "I64d"
#define PRIdPTR "d" #define PRIi8 "i"
#define PRIi16 "i"
#define PRIi32 "i"
#define PRIi64 "I64i" #define PRIiLEAST8 "i"
#define PRIiLEAST16 "i"
#define PRIiLEAST32 "i"
#define PRIiLEAST64 "I64i" #define PRIiFAST8 "i"
#define PRIiFAST16 "i"
#define PRIiFAST32 "i"
#define PRIiFAST64 "I64i" #define PRIiMAX "I64i"
#define PRIiPTR "i" #define PRIo8 "o"
#define PRIo16 "o"
#define PRIo32 "o"
#define PRIo64 "I64o" #define PRIoLEAST8 "o"
#define PRIoLEAST16 "o"
#define PRIoLEAST32 "o"
#define PRIoLEAST64 "I64o" #define PRIoFAST8 "o"
#define PRIoFAST16 "o"
#define PRIoFAST32 "o"
#define PRIoFAST64 "I64o" #define PRIoMAX "I64o" #define PRIoPTR "o" /* fprintf macros for unsigned types */
#define PRIu8 "u"
#define PRIu16 "u"
#define PRIu32 "u"
#define PRIu64 "I64u" #define PRIuLEAST8 "u"
#define PRIuLEAST16 "u"
#define PRIuLEAST32 "u"
#define PRIuLEAST64 "I64u" #define PRIuFAST8 "u"
#define PRIuFAST16 "u"
#define PRIuFAST32 "u"
#define PRIuFAST64 "I64u" #define PRIuMAX "I64u"
#define PRIuPTR "u" #define PRIx8 "x"
#define PRIx16 "x"
#define PRIx32 "x"
#define PRIx64 "I64x" #define PRIxLEAST8 "x"
#define PRIxLEAST16 "x"
#define PRIxLEAST32 "x"
#define PRIxLEAST64 "I64x" #define PRIxFAST8 "x"
#define PRIxFAST16 "x"
#define PRIxFAST32 "x"
#define PRIxFAST64 "I64x" #define PRIxMAX "I64x"
#define PRIxPTR "x" #define PRIX8 "X"
#define PRIX16 "X"
#define PRIX32 "X"
#define PRIX64 "I64X" #define PRIXLEAST8 "X"
#define PRIXLEAST16 "X"
#define PRIXLEAST32 "X"
#define PRIXLEAST64 "I64X" #define PRIXFAST8 "X"
#define PRIXFAST16 "X"
#define PRIXFAST32 "X"
#define PRIXFAST64 "I64X" #define PRIXMAX "I64X"
#define PRIXPTR "X" /*
* fscanf macros for signed int types
* NOTE: if 32-bit int is used for int_fast8_t and int_fast16_t
* (see stdint.h, 7.18.1.3), FAST8 and FAST16 should have
* no length identifiers
*/ #define SCNd16 "hd"
#define SCNd32 "d"
#define SCNd64 "I64d" #define SCNdLEAST16 "hd"
#define SCNdLEAST32 "d"
#define SCNdLEAST64 "I64d" #define SCNdFAST16 "hd"
#define SCNdFAST32 "d"
#define SCNdFAST64 "I64d" #define SCNdMAX "I64d"
#define SCNdPTR "d" #define SCNi16 "hi"
#define SCNi32 "i"
#define SCNi64 "I64i" #define SCNiLEAST16 "hi"
#define SCNiLEAST32 "i"
#define SCNiLEAST64 "I64i" #define SCNiFAST16 "hi"
#define SCNiFAST32 "i"
#define SCNiFAST64 "I64i" #define SCNiMAX "I64i"
#define SCNiPTR "i" #define SCNo16 "ho"
#define SCNo32 "o"
#define SCNo64 "I64o" #define SCNoLEAST16 "ho"
#define SCNoLEAST32 "o"
#define SCNoLEAST64 "I64o" #define SCNoFAST16 "ho"
#define SCNoFAST32 "o"
#define SCNoFAST64 "I64o" #define SCNoMAX "I64o"
#define SCNoPTR "o" #define SCNx16 "hx"
#define SCNx32 "x"
#define SCNx64 "I64x" #define SCNxLEAST16 "hx"
#define SCNxLEAST32 "x"
#define SCNxLEAST64 "I64x" #define SCNxFAST16 "hx"
#define SCNxFAST32 "x"
#define SCNxFAST64 "I64x" #define SCNxMAX "I64x"
#define SCNxPTR "x" /* fscanf macros for unsigned int types */
//感觉这里是无符号
#define SCNu16 "hu"
#define SCNu32 "u"
#define SCNu64 "I64u" #define SCNuLEAST16 "hu"
#define SCNuLEAST32 "u"
#define SCNuLEAST64 "I64u" #define SCNuFAST16 "hu"
#define SCNuFAST32 "u"
#define SCNuFAST64 "I64u" #define SCNuMAX "I64u"
#define SCNuPTR "u"
我感觉gcc这个源码没有Ubuntu哪个那么容易看懂,管他呢……用法是一样的
百度上的例子:
PRIi8、PRIu8、PRIo8以及PRIx8,其中i为有符号,u为无符号,o为8进制以及x为16进制。
百度上的代码:
#include <stdio.h>
#include <inttypes.h> int main() {
int a = ;
printf("a=%"PRIu64"\n", a);
return ;
}
输出是啥我不太明白,感觉像是按位把int 拓展成了long long 导致出现了一个特别奇怪的数
我做了其他的测试
int a = ;
printf("a=%"PRx8"\n", a);
输出的是 f
int a = 0xff;
printf("a=%"PRu8"\n", a);
输出的是255
嘿嘿,真是个进制转换的神器,不过好像没有二进制,而且只有常用的8和16,其他的还得自己写,这个库里还有其他功能,我先研究研究,日后再更新。(现在主要是防止自己忘记)
学习不易,诸君共勉!
C语言拾遗——inttypes.h的更多相关文章
- C语言拾遗——strtok
C语言拾遗——strtok 今天刷PAT的时候用到了这个strtok函数,顺手就记录一下 strtok函数包含于头文件string.h 语法:char *strtok( char *str1, con ...
- 使用ACE遇到无法打开包括文件:“inttypes.h”的解决方案
本来想使用ACE_Get_Opt类来做一个命令行解析的功能,但是当项目中配置好了ACE库的路径后,编译时遇到"无法打开包括文件: inttypes.h : No such file or d ...
- ffmpeg遇到inttypes.h和UINT64_C
http://blog.csdn.net/cll131421/article/details/7763657 编译过程:错误一:无法打开包括文件:“inttypes.h”: No such file ...
- ffmpeg “inttypes.h”: No such file or directory
编译过程:错误一:无法打开包括文件:“inttypes.h”: No such file or directory解决方法:删除之,并在其之前添加如下代码: #if defined(WIN32) &a ...
- C语言拾遗(一)
越来越体会到C语言的重要性,不管是在计算机底层的理解上,还是在算法数据结构上,所以遂决定重新拾起C语言,不定期更新一些知识点. 推荐博客:http://blog.csdn.net/itcastcpp ...
- C语言.c和.h
简单的说其实要理解C文件与头文件(即.h)有什么不同之处,首先需要弄明白编译器的工作过程,一般说来编译器会做以下几个过程: 1.预处理阶段 2.词法与语法分析阶段 3.编译阶段,首先编译成 ...
- C 语言项目中.h文件和.c文件的关系
http://blog.csdn.net/xingkong_678/article/details/38639847 关于两者以前的关系,要从N年以前说起了~ long long ago,once a ...
- windows+vs2017+C语言 引入mysql.h对MYSQL数据库的操作
mysql.h文件用作VS开发用,用来连接数据库.没有mysql.h文件,就无法调用mysql的东西 也无法用C语言对MYSQL操作. 一般安装了mysql之后,这个文件就在mysql目录的inclu ...
- C语言拾遗
1. 没C++那么恶心的const C语言中的const修饰符用于修饰一个变量是const属性的.被C语言的const修饰的变量具有只读属性,并且不能被修改. const修饰的变量 != 常量,con ...
随机推荐
- 启动storm任务时,异常提示
启动storm任务时,异常提示: 14182 [NIOServerCxn.Factory:0.0.0.0/0.0.0.0:2000] WARN o.a.s.s.o.a.z.s.NIOServerCnx ...
- Kubernetes 二进制部署(一)单节点部署(Master 与 Node 同一机器)
0. 前言 最近受“新冠肺炎”疫情影响,在家等着,入职暂时延后,在家里办公和学习 尝试通过源码编译二进制的方式在单一节点(Master 与 Node 部署在同一个机器上)上部署一个 k8s 环境,整理 ...
- boost::program_options 解析命令行参数
源码: #include <boost/program_options.hpp> namespace po = boost::program_options; int main(int a ...
- luogu P2761 软件补丁问题
网络流(x) 状压(√) 初始状态为全1,合法状态为(state&b1)&(state|b1) == state && (state&b2)&(stat ...
- less在vscode中的配置方式
1.在vscode插件中下载easy less这个插件. 2.新建项目,分别建两个文件夹存放less和自动编译好的css,页面中引入文件引css就可以了. 3.根据你的文件位置,在用户设置中设置需要配 ...
- 【转】深入分析JAVA IO(BIO、NIO、AIO)
IO的基本常识 1.同步 用户进程触发IO操作并等待或者轮询的去查看IO操作是否完成 2.异步 用户触发IO操作以后,可以干别的事,IO操作完成以后再通知当前线程继续处理 3.阻塞 当一个线程调用 r ...
- call 和 apply 用法
ECMAScript规范中,所有函数都包含这两个方法,并且两个方法的使用基本一致,都是用于改变函数的作用域,即改变函数体内 this 指向.不同的是 call 方法的第二个参数可以接收任意个参数,以逗 ...
- PE文件结构体-IMAGE_SECTION_HEADER
在PE文件头与原始数据之间存在一个区块表(Section Table),它是一个IMAGE_SECTION_HEADER结构数组, 区块表包含每个块在映像中的信息(如位置.长度.属性),分别指向不同的 ...
- Google宣布安全奖励项目(GPSRP)覆盖上亿的 Android 应用程序
自 2010 年推出除虫赏金项目以来,谷歌已经向安全研究人员支付了超过 1500 万美元的奖励.今天,这家科技巨头宣布进一步拓展 Google Play 安全奖励项目(GPSRP)的范围,以覆盖上亿的 ...
- eclipse springboot运行helloworld错误: 找不到或无法加载主类 xxx.xxx.xxx
这个错误,在网上搜找了好久,说是什么jar包冲突,什么环境配置,我经过验证均是正确的,javac java java -version 都没问题,环境变量也OK,各种解释均没有能够解决我的问题,最后好 ...