Question

can someone explain the difference between the types uint8_t and __u8 ?

i know that uint8_t are defined in stdint.h and they are available on every unix system.

/* Unsigned.  */
typedef unsigned char       uint8_t;
typedef unsigned short int  uint16_t;
...

And if i use them its recognizable what i intent to do.

now i stumbled over the __u8 and __u16 types. its seems for me to be the same.

some of those types are defined in linux/types.h

#ifdef __CHECKER__
#define __bitwise__ __attribute__((bitwise))
#else
#define __bitwise__
#endif
#ifdef __CHECK_ENDIAN__
#define __bitwise __bitwise__
#else
#define __bitwise
#endif

typedef __u16 __bitwise __le16;
typedef __u16 __bitwise __be16;
typedef __u32 __bitwise __le32;
...

i didnt find __u8 but i can still use it and it behaves like uint8_t.

is there some difference in performance or memory consumption?

thanks for help :)

Was it helpful?

Solution

uintn_t are typedefs specified* by C99 (in <stdint.h>) and C++11 (in <cstdint>) standards. All new compilers provide these and appopriate definition is easy to get for the few ancient ones easily, so for portability always use this.

__un are Linux-specific typedefs predating those standards. They are not portable. The double underscore is used to signify a non-standard definition.

* For 8, 16, 32 and 64 they shall be defined if the compiler has a type of that size, additional ones may be defined.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top