u16
首先必须知道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 charu_char;
typedef unsigned shortu_short;
typedef unsigned intu_int;
typedef unsigned longu_long;
/* sysv */
typedef unsigned charunchar;
typedef unsigned shortushort;
typedef unsigned intuint;
typedef unsigned longulong;
#ifndef __BIT_types_defined__
#define __BIT_TYPES_DEFINED__
typedef__u8u_int8_t;
typedef__s8int8_t;
typedef__u16u_int16_t;
typedef__s16int16_t;
typedef__u32u_int32_t;
typedef__s32int32_t;
#endif /* !(__BIT_TYPES_DEFINED__) */
typedef__u8uint8_t;
typedef__u16uint16_t;
typedef__u32uint32_t;
#if defined(__GNUC__)
typedef__u64uint64_t;
typedef__u64u_int64_t;
typedef__s64int64_t;
对于各种数据类型的打印方式总结如下如下:
数据类型
打印格式
u8
%d
s8
%d
u16
%d or %hu
s16
%d or %hd
u32
%u
s32
%d
u64
%llu
s64
%lld
int
%d
unsigned int
%u
short int
%d or %hd
long
%ld
unsigned long
%lu
long long
%lld
unsigned long long
%llu
char
%c
char *
%s
bool (#define stdbool.h)
%d
unsigned int/int------>十六进制
%0x
unsigned long/long---->十六进制
%0lx
long long/unsigned long long ----->十六进制
%0llx
unsigned int/int------>八进制
%0o
unsigned long/long---->八进制
%0lo
long long/unsigned long long ----->八进制
%0llo
float
%f
double
%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 true1
#define false0
#else /* __cplusplus */
/* Supporting _Bool in C++ is a GCC extension. */
#define _Boolbool
#if __cplusplus < 201103L
/* Defining these macros in C++98 is a GCC extension. */
#define boolbool
#define falsefalse
#define truetrue
#endif
#endif /* __cplusplus */
/* signal that all the definitions are present. */
#define __bool_true_false_are_defined1
#endif/* stdbool.h */
也大致解释了linux kernel bool type了。
相关阅读
c++ ostringstream的用法(c语言的sprintf)
转载: https://blog.csdn.net/qq1987924/article/details/7671154ostringstream的用法【本文来自】http://www.builder.com.cn/20
C语言中的scanf()和printf()函数
C语言中的输入、输出函数,在C++中一直使用cin、cout,对scanf和printf的使用不太熟悉,现做以下整理。
scanf()函数详解
函数名:sc
printf(),fprintf(),perror()
在C语言,linux中都会遇到这几个函数printf(),fprintf(),perror() 那么和上述三个函数对应的就是stdin,stdout,stderr。0就是stdin,表示输入流
fprintf()函数的运用
fprintf()用于文件操作
#include
int fprintf( FILE *stream, const char *format, ... );
fprintf()函数根据
C 语言printf打印各种数据类型的方法(u8/s8/u16/s16..
首先必须知道u8,s8等数据类型的定义:typedef signed char s8;
typedef unsigned char u8;
typedef signed short s16;
ty