无法在GCC中为IntType定义MAX值

The*_* do -1 c++ gcc

为什么这在GCC 4.5.1中不起作用

#include <iostream>  
#include <type_traits>
#include <limits.h>//for INT_MIN
#include <typeinfo>
using namespace std;

#ifdef _MSC_VER
#define UNIVERSAL_INT_MAX LLONG_MAX
#define UNIVERSAL_INT_MIN LLONG_MIN
#endif

#ifdef __GNUC__
#define UNIVERSAL_INT_MAX LONG_LONG_MAX  
#define UNIVERSAL_INT_MIN LONG_LONG_MIN
#endif
using namespace std;

int main()
{
    cout << UNIVERSAL_INT_MAX << '\n';
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

我得到的错误:

"main.cpp|24|error: 'LONG_LONG_MAX' was not declared in this scope"  
Run Code Online (Sandbox Code Playgroud)

编辑

#ifdef __GNUC__
#define UNIVERSAL_INT_MAX ( ( 1ULL << numeric_limits< long long >::digits ) - 1 )
#define UNIVERSAL_INT_MAX_plus_three (UNIVERSAL_INT_MAX + 3)
#endif
using namespace std;

int main()
{
    cout << UNIVERSAL_INT_MAX << '\n';
    cout << "Huhh?: " << UNIVERSAL_INT_MAX_plus_three << '\n';
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

Pot*_*ter 6

long long是非标准的,所以LONG_LONG_MAX是非标准的.

最好使用C++机制numeric_limits< long long >::max(),这是在<limits>.

long long 仍然是非标准的,但如果编译器实现它,这保证可以工作.

编辑:您可以使用编译时常量实现相同的功能

( ( 1ULL << numeric_limits< long long >::digits ) - 1 )
Run Code Online (Sandbox Code Playgroud)