The difference between u8, uint8_t, __u8 and __be8

While looking at linux network code, I came across these data types:

  • u8
  • uint8_t
  • __ u8
  • __ Be8

(same for 16, 32 and 64 bit)

Can someone explain the difference between these data types and where to use them? I saw the definitions of these data types, but this was not clear to me.

+5
source share
2 answers

uint8_t is a C standard and is an unsigned 8-bit integral type. If you are on a system that does not have 8-bit addressable units, this will not be determined; otherwise it is probably a typedef for an unsigned char .

Everything with __ in it is reserved for use. This means that compiler authors and standard libraries can use these identifiers without worrying about name conflicts with user code. You can see this when viewing the internal components of the standard library implementation.

u8 is non-standard, but almost certainly means the same as uint8_t . The reason u8 can be used is u8 code was written before uint8_t was added to the C standard.

+9
source

The latter stands for big-endian (not important for a single byte), the so-called network byte order.

All are all identical to each other, unsigned type 8 bits / 1 byte.

Above everything is done for those types with 16 bits / 2 bytes respectively. 32 bits / 4 bytes.

(The host byte order on x86, for example, is not very similar, and Linux only works on 8-bit machines.)

From the list, only uint8_t is defined by the C standard (in <stdint.h ), and the last two are in the namespace of the implementations, which is usually bad.

+1
source

Source: https://habr.com/ru/post/1206685/


All Articles