Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

difference between __u8 and uint8_t

Tags:

c++

types

stdint

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 :)

like image 950
baam Avatar asked Apr 26 '13 09:04

baam


People also ask

What is __ uint8_t?

A UINT8 is an 8-bit unsigned integer (range: 0 through 255 decimal).

What is the difference between Uint8 and uint8_t?

The difference between Uint8 and uint8_t will depend on implementation, but usually they will both be 8 bit unsigned integers. Also uint8_t and uint16_t are defined by C (and maybe C++) standard in stdint. h header, Uint8 and Uint16 are non-standard as far as I know.

Does u8 mean unsigned 8-bit?

u8 : The 8-bit unsigned integer type. u16 : The 16-bit unsigned integer type. u32 : The 32-bit unsigned integer type. u64 : The 64-bit unsigned integer type.

What is __ u32 in C?

__u32 undeclaredexcept for the problem of too many layers of indirection.


1 Answers

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.

like image 190
Jan Hudec Avatar answered Sep 30 '22 13:09

Jan Hudec