Where to check if type long long is defined? I wanna do something like this:
#ifdef LONGLONG
#define long_long long long
#else
#define long_long long
#endif
long long is used for storing 64 bit integers where as int can only store 16 bit integers.
long and long int are identical. So are long long and long long int . In both cases, the int is optional.
LongLong (LongLong integer) variables are stored as signed 64-bit (8-byte) numbers ranging in value from -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807. The type-declaration character for LongLong is the caret (^). LongLong is a valid declared type only on 64-bit platforms.
In some cases we use long long in C or C++. Here we will see what is basically long long is? The long long takes twice as much memory as long. In different systems, the allocated memory space differs.
LLONG_MAX
gives the maximum value representable by a long long
; if your implementation doesn't support long long
, it shouldn't define LLONG_MAX
.
#include <limits.h>
#ifdef LLONG_MAX
#define long_long long long
#else
#define long_long long
#endif
This isn't a perfect solution. long long
isn't standard in C++03, and long long
has been around longer than C99, so it's possible (and likely) that a compiler could support long long
but not define LLONG_MAX
.
If you want an integer type with a specific size, you should use <stdint.h>
if your implementation supports it. If your implementation doesn't support it, Boost has an implementation of it.
Rather than worry about whether or not a type with that name is defined, I'd #include <climits>
and check whether or not you can find an integer type large enough for your intended use. (Although you could probably just check if LLONG_MAX
is defined to find out if long long
exists.)
Edit: Or, if you can assume C99 headers and types to be available, #include <cstdint.h>
and use e.g. int64_t
to get a 64-bit type or int_fast64_t
to get a “fast” 64-bit type (by some compiler-specific definition of fast). Or intmax_t
if you want the largest available type.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With