问题描述
我看到内核代码中使用了u8 u16 u32 u64数据类型.我想知道为什么需要使用u8
或u16
或u32
或u64
而不是unsigned int
?
I see u8 u16 u32 u64 data types being used in kernel code. And I am wondering why is there need to use u8
or u16
or u32
or u64
and not unsigned int
?
推荐答案
通常在靠近硬件工作或试图控制数据结构的大小/格式时,您需要精确控制整数的大小.
Often when working close to the hardware or when trying to control the size/format of a data structure you need to have precise control of the size of your integers.
对于u8
与uint8_t
,这仅仅是因为Linux早于<stdint.h>
在C语言中可用,从技术上讲,它是一种C99主义,但是以我的经验,即使是在ANSI-中,大多数现代编译器也可以使用它. C/C89模式.
As for u8
vs uint8_t
, this is simply because Linux predated <stdint.h>
being available in C, which is technically a C99-ism, but in my experience is available on most modern compilers even in their ANSI-C / C89 modes.
这篇关于为什么在内核编程中使用u8 u16 u32 u64代替unsigned int的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!