C 语言printf打印各种数据类型的方法(u8/s8/u16/s16.../u64/double/float)(全)

您所在的位置:网站首页 fprintf有什么用 C 语言printf打印各种数据类型的方法(u8/s8/u16/s16.../u64/double/float)(全)

C 语言printf打印各种数据类型的方法(u8/s8/u16/s16.../u64/double/float)(全)

2024-06-04 05:36| 来源: 网络整理| 查看: 265

首先必须知道u8,s8等数据类型的定义:

typedef signed char s8; typedef unsigned char u8; typedef signed short s16; typedef unsigned short u16; typedef signed int s32; typedef unsigned int u32; typedef signed long long s64; typedef unsigned long long u64;

与体系结构相关的,定义在include/linux/type.h文件中:

/* bsd */ typedef unsigned char u_char; typedef unsigned short u_short; typedef unsigned int u_int; typedef unsigned long u_long; /* sysv */ typedef unsigned char unchar; typedef unsigned short ushort; typedef unsigned int uint; typedef unsigned long ulong; #ifndef __BIT_TYPES_DEFINED__ #define __BIT_TYPES_DEFINED__ typedef __u8 u_int8_t; typedef __s8 int8_t; typedef __u16 u_int16_t; typedef __s16 int16_t; typedef __u32 u_int32_t; typedef __s32 int32_t; #endif /* !(__BIT_TYPES_DEFINED__) */ typedef __u8 uint8_t; typedef __u16 uint16_t; typedef __u32 uint32_t; #if defined(__GNUC__) typedef __u64 uint64_t; typedef __u64 u_int64_t; typedef __s64 int64_t;

对于各种数据类型的打印方式总结如下如下:

数据类型打印格式u8%ds8%du16%d or %hus16%d or %hdu32%us32%du64%llus64%lldint%dunsigned int%ushort int%d or %hdlong%ldunsigned long%lulong long%lldunsigned long long%lluchar%cchar *%sbool (#define stdbool.h)%dunsigned int/int------>十六进制%0xunsigned long/long---->十六进制%0lxlong long/unsigned long long ----->十六进制%0llxunsigned int/int------>八进制%0ounsigned long/long---->八进制%0lolong long/unsigned long long ----->八进制%0llofloat%fdouble%f or %lf科学技术类型(必须转化为double类型)%e限制输出字段宽度%x.yf (x:整数长度,y:小数点长度)

待解问题,在linux kernel里面也有使用bool来定义变量,查看code,定义如下:

typedef _Bool bool;

但是并没有真正找到具体定义在何处,待解。下面是stdbool.h的source code:

#define _STDBOOL_H #ifndef __cplusplus #define bool _Bool #define true 1 #define false 0 #else /* __cplusplus */ /* Supporting _Bool in C++ is a GCC extension. */ #define _Bool bool #if __cplusplus < 201103L /* Defining these macros in C++98 is a GCC extension. */ #define bool bool #define false false #define true true #endif #endif /* __cplusplus */ /* Signal that all the definitions are present. */ #define __bool_true_false_are_defined 1 #endif /* stdbool.h */

也大致解释了linux kernel bool type了。 如果大家有兴趣,可以扫码关注我的个人公众号: Linux内核调度器



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3