error: 'INT32_MAX' was not declared in this scope

Viewed 69162

I'm getting the error

error: 'INT32_MAX' was not declared in this scope

But I have already included

#include <stdint.h>

I am compiling this on (g++ (GCC) 4.1.2 20080704 (Red Hat 4.1.2-44) with the command

g++ -m64 -O3 blah.cpp

Do I need to do anything else to get this to compile? or is there another C++ way to get the constant "INT32_MAX"?

Thanks and let me know if anything is unclear!

10 Answers

Hm... All I needed to do was #include <climits> nothing else on this page worked for me.

Granted, I was trying to use INT_MIN.

#include <iostream>
#include <limits.h> or <climits>

worked for me

I was also facing the similar problem,just need to add- #include <limits.h> after #include <iostream>

I ran into similar issue while using LLVM 3.7.1 c++ compiler. Got the following error while trying to compile gRPC code as part of building some custom library

src/core/lib/iomgr/exec_ctx.h:178:12: error: use of undeclared identifier 'INT64_MAX'

The compilation went through after adding -D__STDC_LIMIT_MACROS as one of the options to c++ compiler.

.../bin/c++ -D__STDC_LIMIT_MACROS -I{LIBRARY_PATHS} testlib.cc -o testlib

The code for all c++ version, compatible with lower GCC like CentOS 6.0(gcc version 4.4.7):

// https://onlinegdb.com/ApNzDNYUx

#include <stdio.h>

// @see https://stackoverflow.com/a/9162072/17679565
#include <inttypes.h>

// For CentOS 6(gcc version 4.4.7) or not defined the macro.
#ifndef INT32_MAX
#define INT32_MAX (2147483647)
#endif

int main()
{
    printf("INT32_MAX=%d\n", INT32_MAX);

    return 0;
}

OnlineGDB

include --> #include <bits/stdc++.h> <--

should look like :

#include<iostream>
using namespace std;
#include <bits/stdc++.h>
#include<bits/stdc++.h>

add this at the beginning.

Related