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
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
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
#elif
#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.