Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++: int64_t where does it come from? [duplicate]

Tags:

c++

I was wondering where types like int64_t come from. Are they c++ standard or os-dependent? (1)

Also, do you know where I can find documentation about these types? I couldn't find useful information so far. Do they have a special name? (2)

What's their general difference with regards to the standard primitive types like int,long... (3)

Thank you and Regards

like image 655
ben Avatar asked Dec 25 '13 13:12

ben


People also ask

Is int64_t same as long?

In a 64-bit compile, int64_t is long int , not a long long int (obviously).

What is int64_t?

A long on some systems is 32 bits (same as an integer), the int64_t is defined as a 64 bit integer on all systems (otherwise known as a long long). Portability may be affected using long, but using int64_t looks like it was created to increase portability.

What is int_fast64_t?

int_fast64_t is the data type with at least 64 bits and the best arithmetic performance. It's there mainly for consistency with int_fast8_t and int_fast16_t , which on many machines will be 32 bits, not 8 or 16.


3 Answers

It comes from a header file:

#include <stdint.h> // C standard library
#include <cstdint> // C++ standard library

like image 111
egur Avatar answered Oct 16 '22 17:10

egur


int64_t is typedef you can find that in

   <cstdint>
like image 39
user3134167 Avatar answered Oct 16 '22 17:10

user3134167


They were introduced by C99 standard.

Documentation:
http://www.cplusplus.com/reference/cstdint/
http://en.cppreference.com/w/c/types/integer

They were introduced because the standard doesn't specify fixed width for standard primitives, but a minimum width. So int can be 16-bit or 32-bit, depending on compiler, OS, and architecture, long varies as well as it can be 32-bit or 64-bit. Even char can be 8 or 16 bits.

like image 3
bolov Avatar answered Oct 16 '22 17:10

bolov