error: 'INT32_MAX' was not declared in this scope

后端 未结 7 1293
谎友^
谎友^ 2020-12-03 06:56

I\'m getting the error

error: \'INT32_MAX\' was not declared in this scope

But I have already included

#include 

        
相关标签:
7条回答
  • 2020-12-03 07:08

    Quoted from the man page, "C++ implementations should define these macros only when __STDC_LIMIT_MACROS is defined before <stdint.h> is included".

    So try:

    #define __STDC_LIMIT_MACROS
    #include <stdint.h>
    
    0 讨论(0)
  • 2020-12-03 07:13

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

    0 讨论(0)
  • 2020-12-03 07:20
     #include <cstdint> //or <stdint.h>
     #include <limits>
    
     std::numeric_limits<std::int32_t>::max();
    

    Note that <cstdint> is a C++11 header and <stdint.h> is a C header, included for compatibility with C standard library.

    Following code works, since C++11.

    #include <iostream>
    #include <limits>
    #include <cstdint>
    
    struct X 
    { 
        static const std::int32_t i = std::numeric_limits<std::int32_t>::max(); 
    };
    
    int main()
    {
        switch(std::numeric_limits<std::int32_t>::max()) { 
           case std::numeric_limits<std::int32_t>::max():
               std::cout << "this code works thanks to constexpr\n";
               break;
        }
        return EXIT_SUCCESS;
    }
    

    http://coliru.stacked-crooked.com/a/4a33984ede3f2f7e

    0 讨论(0)
  • 2020-12-03 07:22

    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
    
    0 讨论(0)
  • 2020-12-03 07:23

    Including the following code after #include <iostream> worked for me:

    #include <limits.h>
    

    I am using the following compiler:

    g++ 5.4.0-6

    0 讨论(0)
  • 2020-12-03 07:28

    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.

    0 讨论(0)
提交回复
热议问题