Why uint_8 etc. Used in C / C ++?

I saw some code where they do not use the primitive types int, float, double, etc. directly. Usually they typify it and use or use things like uint_8, etc.

Is it really necessary even these days? Or C / C ++ is so standardized that it is preferable to use int, float, etc. Directly.

+3
source share
7 answers

Since the types of type char, short, int, longetc. are ambiguous: they depend on the underlying equipment. Back in the days when C was generally considered an assembly language for people in a hurry, everything was in order. Now for writing programs that are portable, which means "programs that mean the same thing on any machine" - people have created special libraries typedefsand #definesthat allow them to create machine independent definitions.

The secret code is really pretty straight forward. Here you have uint_8, which is interpreted

  • u for unsigned
  • int say it is regarded as a number
  • _8 for size in bits.

In other words, this is an unsigned integer with 8 bits (minimum) or what we used to invoke the history of C, "unsigned char".

+14

uint8_t , - , unsigned char 8-, unsigned char. , , . int (, , ) 32- , 16-, 64- int - 64-. , DSP.

32- , int32_t uint32_t .. , , ...

+4

, , typedefs , .

, , 32- , typedef, 32-, .

int16 int64, , , . int.

"int i" for, "int32". - "" ( " " ) C/++, 16- "int" , C/++ , 16- . , , "int" 16 , , , . , "int" int .

+3

C ++ int. , .

int , , , , . , uint_8, , ( ) 8- .

+2

, ++. , , , uint_8 , ( ), ..

+1

C . 64- - : 64- long long, __int64 int . , C99 <stdint.h>, , int32_t, , 32 ; typedefs .

+1

C ++ , , . , int , .

, , . int , ints.

. 64- , . , , . , , typedef , .

0

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


All Articles