C语言中各种类型所占字节_C语言简单数据类型

C语言中各种类型所占字节_C语言简单数据类型首先必须知道u8,s8等数据类型的定义:typedefsignedchars8;typedefunsignedcharu8;typedefsignedshorts16;typedefunsignedshortu16;typedefsignedints32;typedefunsignedintu32;typedef…

大家好,又见面了,我是你们的朋友全栈君。如果您正在找激活码,请点击查看最新教程,关注关注公众号 “全栈程序员社区” 获取激活教程,可能之前旧版本教程已经失效.最新Idea2022.1教程亲测有效,一键激活。

Jetbrains全系列IDE稳定放心使用

首先必须知道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 %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 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内核调度器

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/181632.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • VS2013产品密钥

    VS2013产品密钥VS2013试用期结束需要提供产品密钥进行注册,下面将提供几个好用的产品密钥。首先打开VS-&amp;amp;gt;帮助-&amp;amp;gt;注册产品-&amp;amp;gt;输入产品密钥BWG7X-J98B3-W34RT-33B3R-JVYW9(亲测有效)下面几个VS版本楼主未使用过,大家可以使用一下试试。VisualStudioUltimate2013KEY(密钥):BWG7X-J98B3-W34RT-33B3…

    2022年5月20日
    111
  • js中的prototype的解析

    js中的prototype的解析js的方法可以分为三种:对象方法、类方法、prototype方法//对象方法functionPeople(name){this.name=name;this.introduct=function(){alert(“Mynameis”+this.name);console.log(“Mynameis”+this.name);}}//类方法Peop

    2022年7月23日
    7
  • 电子元器件常用品牌汇总(持续更新)

    电子元器件常用品牌汇总(持续更新)电阻:Yageo国巨、Fenghua风华、Rohm罗姆、TDK、Samsung三星、Uniohm厚声、Walsin华新科、Ralec旺诠、KOA兴亚、Panasonic松下、AVX、TMTEC泰铭、Kyocera京瓷、PHYCOM飞元。电容:Yageo国巨、Fenghua风华、Murata村田、TDK、Samsung三星、Eyang宇阳、Taiyo太诱、Kyocera京瓷、HEC禾伸堂、Kemet基美、ISND华信安、AVX、Nichicon尼吉康、Panasonic松下、SANYO三洋。电感:Mura

    2022年6月29日
    38
  • linux下安装node&npm

    linux下安装node&npm#下载最新版nodewgethttps://nodejs.org/dist/v16.14.0/node-v16.14.0-linux-x64.tar.xz#解压tar-xvfnode-v16.14.0-linux-x64.tar.xz#配置软连接,使全局都可以使用node命令sudoln-s/opt/node-v16.14.0-linux-x64/bin/node/usr/bin/nodesudoln-s/opt/node-v16.14.0-linux-x64/bin/

    2022年8月30日
    5
  • Ubuntu安装超好用的Edge浏览器

    Ubuntu安装超好用的Edge浏览器Edge与Chrome都基于开源浏览器Chromium。但是Chrome由与众所周知的原因,扩展商店,翻译等服务延迟高,并不好用。相比较Edge体验起来会更流畅。但是通过官方地址https://www.microsoft.com/zh-cn/edge并没有Linux版本。这里可以通过https://www.microsoftedgeinsider.com/zh-cn/下载官方内部版本。…

    2022年7月21日
    30
  • python怎么安装matplotlib.pyplot_python安装matplotlib模块

    python怎么安装matplotlib.pyplot_python安装matplotlib模块总结经验,前排感谢CSDN大神…一、在Pycharm中安装matplotlib1、打开AnacondaPrompt,输入pipinstallmatplotlib输入pipinstallmatplotlib==3.3.0限制下载的版本为3.3.0.这是为了防止版本过新,之后在PyCharm运行时出现问题。2、打开PyCharm(1)依次点击File-Settings-…

    2022年8月25日
    10

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号