single, comprehensive kernel data types document?
Nicholas Mc Guire
der.herr at hofr.at
Fri Apr 15 11:59:09 EDT 2016
On Fri, Apr 15, 2016 at 05:27:24AM -0700, Greg KH wrote:
> On Fri, Apr 15, 2016 at 08:04:53AM -0400, Robert P. J. Day wrote:
> >
> > is there a single, decent online doc that explains the proper data
> > types (int16_t, int32_t and so on) to use in kernel code?
>
> First off, never use int16_t and friends, that's not ok :)
>
> Second, it's simple, use:
> u8
> u16
> u32
> u64
> and friends in kernel code (s8, s16, and so on for signed values.)
>
I don´t think its quite that simple - as an exampe here is a part of the
variations of chars that exist in the kernel:
Type : equivalent types (basis 4.0 x86 64)
char : signed char, __signed__ char, __s8, s8, int8_t
unsigned char : unsigned char, u_char, __u8, u8, unchar, u_int8_t, uint8_t
__ticket_t,
insn_byte_t,
kprobe_opcode_t
Now for new unsigned char objects it might be good enough to simply use
u8 but it does depend on the subsystem and if that has some typedef in
use or not or readability could really suffer.
It would however make a lot of sense I belive if a list of types that
should be used and which should no longer be used were available.
Probably a number of the above typedef might actually be deprecated for
any new code (and char is actually one of the shorter lists - unsigned
short, unsigned int, unsigned long have atleast 25 equivalent typedefs
each).
So a typedef cleanup would make a lot of sense for new conributors and it
would also help readability as well as make static code analysis easier...
If the above recommendation {u,s}{8,16,32,64} is somehow official policy
for new code, then it maybe should go into Documentation/CodingStyle ?
thx!
hofrat
More information about the Kernelnewbies
mailing list