Error: 'Int32_Max' Was Not Declared in This Scope

error: 'INT32_MAX' was not declared in this scope

 #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 constexpr 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

‘INTMAX_MAX’ was not declared in this scope

Well, first and foremost, you are compiling your code as C++. Since these macros originate from C99, they can theoretically end up conflicting with existing C++ definitions for the same names. For which reason GCC compiler plays it safe: it wants you to explicitly request these macro definitions before they become available.

In my GCC installation the macro definitions are protected by

#if (!defined __cplusplus || __cplusplus >= 201103L \
|| defined __STDC_LIMIT_MACROS)

Since you are apparently compiling your code as pre-C++11 C++, you have to request these macros by defining __STDC_LIMIT_MACROS before including stdint.h. But at the same time your code will compile "as is" if you run the compiler in -std=c++11 mode.

Also see What do __STDC_LIMIT_MACROS and __STDC_CONSTANT_MACROS mean?

‘ULONG_MAX’ was not declared in this scope

ULONG_MAX is defined in the limits.h header file. Putting #include <climits> in with your other includes should fix the issue.

Error: ‘numeric_limits’ was not declared in this scope

You need to include

    #include <limits>

error: FILE was not declared in this scope

Hi fopen is a function from C I/O standard library (stdio.h).

If you would use that function, in your C++ program, you must include that library #include <cstdio>.

But in the title you wrote C++, so in this case you can use iostream or fstream like

#include <iostream>
#include <fstream>

Read more here: fopen, stdio.h, cstdio, fstream, iostream.

Good luck!



Related Topics



Leave a reply



Submit