Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Uses and when to use int16_t,int32_t,int64_t and respectively short int,int,long int,long

Tags:

c++

types

integer

Uses and when to use int16_t, int32_t, int64_t and respectively short, int, long.
There are too many damn types in C++. For integers when is it correct to use one over the other?

like image 708
shovel_boss Avatar asked Aug 10 '16 01:08

shovel_boss


People also ask

What is the use of int32_t?

That's where int32_t comes in: it's an alias for whatever integer type your particular system has that is exactly 32 bits. Template: intN_t or uintN_t Where N is width of integer which can be 8, 16, 32, 64 or any other type width supported by the library.

What's the difference between int and int16_t?

If int = 16 bit then obviously there is no difference between int and int16_t. So since int cannot be less than 16 bit, we may assume that int is more than 16 bit. Being more than 16 bit makes it more useful than int16_t. After all, it can hold more values.

Is int64_t same as long long?

The __int8 data type is synonymous with type char , __int16 is synonymous with type short , and __int32 is synonymous with type int . The __int64 type is synonymous with type long long .

What does int16_t mean?

unit8_t means 8bits unsigned int(that is 8 bits of only positive integers) int16_t means 16 bit of signed int(int could be positive or negative). 8 bits = 1byte and 16bits = 2 bytes. 3.


1 Answers

Use the well-defined types when the precision is important. Use the less-determinate ones when it is not. It's never wrong to use the more precise ones. It sometimes leads to bugs when you use the flexible ones.

like image 126
Blair Houghton Avatar answered Oct 13 '22 19:10

Blair Houghton