Issue
I'm writing some code using the Joystick API of the linux kernel. In the examples in the readme it says to use this syntax:
struct js_event {
__u32 time;
__s16 value;
__u8 type;
__u8 number;
};
Yet when I use gcc to build the code that I've written this produces an error. I don't actually know what the __u32
part means.
I then Googled a bit and found this
If you include stdint.h then you get int8_t, uint8_t, int16_t, uint16_t, etc. They're standard C, even if it is the newer, less-implemented standard. I'd recommend using stdint.h if you can, since it's less system-specific than types like __u8.
So could someone give me a list of the new types and what they mean? Also a lowdown on what roles types actually have.
Solution
__u32
and friends are integer types defined in <asm/types.h>
that are specific to the Linux Kernel.
__u32
is an unsigned 32-bit integer.
__s16
is a signed 16-bit integer.
__u8
is an unsigned 8-bit integer, and so on.
As you are writing code using the Linux kernel API anyways, you don't need to care about portability, and should stick to the Linux APIs and types.
Just don't forget to
#include <asm/types.h>
Also see pointer to __u32 in a header file.
Answered By - SirDarius Answer Checked By - Mildred Charles (WPSolving Admin)