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)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • 递归和迭代有什么区别?

    递归和迭代有什么区别?“递归”和“迭代”的区别如下:1、递归的基本概念:程序调用自身的编程技巧称为递归,是函数自己调用自己.一个函数在其定义中直接或间接调用自身的一种方法,它通常把一个大型的复杂的问题转化为一个与原问题相似的规模较小的问题来解决,可以极大的减少代码量.递归的能力在于用有限的语句来定义对象的无限集合。2、迭代:利用变量的原值推算出变量的一个新值.如果递归是自己调用自己的话,迭代就是A不停的调用…

    2022年6月6日
    36
  • Java + Ajax跨域解决方案整理

    Java + Ajax跨域解决方案整理为什么会跨域呢?简单来说就是前端页面与后台服务没有部署在同一个服务器上。产生跨域的情况有:1.域名不同,端口也不同;2.域名相同但是端口不同;3.域名不同,端口相同。解决方案:一、JSONP方式1.只支持get方法,不支持postfang方法;使用时需修改前端和后端代码,用起来也不太方便,本文不推荐使用。二、使用springMVC架构的,使用版本4.2以上…

    2022年8月24日
    6
  • 至强e5处理器天梯图_e系列cpu天梯图

    至强e5处理器天梯图_e系列cpu天梯图lintel的至强CPU(Xeon)是为服务器准备的,优点核心数、线程数超多,对多任务处理优势明显,现在很多桌面电脑也会搭配志强CPU,用于游戏挂机,多任务处理等等。那么你们知道至强CPU性能排行榜,志强CPU中哪个最强,感兴趣的朋友一起来看看至强系列cpu天梯图,由本站2020年6月发布。至强CPU单线程跑分和多线程跑分性能排行榜:至强系列cpu天梯图2020:(数据比较多,大家可以使用CTR…

    2022年9月20日
    2
  • mybatis-log-plus 激活码【2022最新】2022.03.03

    (mybatis-log-plus 激活码)JetBrains旗下有多款编译器工具(如:IntelliJ、WebStorm、PyCharm等)在各编程领域几乎都占据了垄断地位。建立在开源IntelliJ平台之上,过去15年以来,JetBrains一直在不断发展和完善这个平台。这个平台可以针对您的开发工作流进行微调并且能够提供…

    2022年4月2日
    463
  • canoe入门教程_canoe编程

    canoe入门教程_canoe编程转自:https://www.cnblogs.com/fengliu-/p/7844072.htmlCANOE入门(一)CANoe是Vector公司的针对汽车电子行业的总线分析工具,现在我用CANoe7.6版本进行介绍,其他版本功能基本差不多。硬件我使用的是CANcaseXL.1,CANoe软件的安装很简单,先装驱动,再装软件。安装完成,插上USB,连接硬件,这样在控制面板中,…

    2025年7月1日
    3
  • PAT准备之2018.7.24

    昨天被我划水滑过去了,今天终于完成了救赎,基本没有划水,一直在认真的学习,今天也做了不少题,发现自己还是有很多知识点薄弱的地方,还是基础不太好吧,以前总觉得自己这些东西都会,结果发现真到自己用的时候,真的是不会。。。唉!这个暑假再把基础知识补一补吧。今天也是做了三道题。如下1007MaximumSubsequenceSum(25)(25分)Givenasequenceo…

    2022年4月9日
    51

发表回复

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

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