Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there long long defined?

Tags:

c++

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
like image 565
There is nothing we can do Avatar asked May 14 '10 19:05

There is nothing we can do


People also ask

What is define long long?

long long is used for storing 64 bit integers where as int can only store 16 bit integers.

Is long long int same as long long?

long and long int are identical. So are long long and long long int . In both cases, the int is optional.

What is long long type?

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.

Is there long long in C?

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.


2 Answers

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.

like image 115
James McNellis Avatar answered Oct 02 '22 19:10

James McNellis


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.

like image 44
Arkku Avatar answered Oct 02 '22 18:10

Arkku