2

I am getting this error while compiling a cpp file in GCC 4.8.1 in ubuntu

‘ULONG_MAX’ was not declared in this scope'

the code am trying to compile

header included

#include <algorithm>
#include <map>
#include <set>
#include <iostream>
#include <cstdlib>
#include <cerrno>
#include <cstring>



bool parser<unsigned>::parse(Option &O, const char *ArgName,
                             const std::string &Arg, unsigned &Value) {
  char *End;
  errno = 0; 
  unsigned long V = strtoulul(Arg.c_str(), &End, 0);
  Value = (unsigned)V;
  if (((V == ULONG_MAX) && (errno == ERANGE)) || (*End != 0) || (Value != V))
    return O.error(": '" + Arg + "' value invalid for uint argument!");
  return false;
}

I tried the help from the link error: 'INT32_MAX' was not declared in this scope but I couldn't match to my case

Community
  • 1
  • 1
  • 2
    You need the header `` – juanchopanza Sep 11 '14 at 13:23
  • 2
    You might want to move on to the more modern [`std::numeric_limits`](http://en.cppreference.com/w/cpp/types/numeric_limits). – Biffen Sep 11 '14 at 13:24
  • 4
    For the future, the reason you are getting downvotes is because typing `ULONG_MAX` into Google would give you an answer instantly. – TartanLlama Sep 11 '14 at 13:43
  • @Tartan: Regarding your comment (and directing to the down voters, not you): Stack Overflow's mission is to be a repository for answers related to programming and development. It does not matter what Google answers with. In fact, Google returned this Stack Overflow question as the number one hit when I Google it. Confer, [C++ ULONG_MAX](https://www.google.com/search?q=C%2B%2B+ULONG_MAX). The down voters are just typical uninformed and opinionated Stack Overflow members who are going to be heard regardless of how useless the message is (much like this message :) – jww Oct 27 '15 at 09:48
  • @Biffen - `numeric_limits` are not a "compile time constant" or `constexpr`. Clang will *not* optimize them properly under some conditions you would expect. I believe you need the `#define` for best performance. – jww Oct 27 '15 at 09:56
  • @jww True, but I don't think StackOverflow exists to document what headers define what (at least until we get the Documentation area). And `std::numeric_limits::max/min` *are* `constexpr`. – TartanLlama Oct 27 '15 at 16:07

1 Answers1

10

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

TartanLlama
  • 63,752
  • 13
  • 157
  • 193
  • I believe there are some C++ version requirements that need to be honored when attempting to use ``. – jww Oct 27 '15 at 09:44