Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

246
Views
min and max in legacy C++

I am trying to compile some older C++ code (probably from around 2001-2002) on a Debian GNU/Linux stable system. When compiling, I get the error:

In file included from /usr/include/c++/4.7/vector:66:0,
                 from ../FooMath/FooBar.h:23,
                 from FooBar.cpp:2:
/usr/include/c++/4.7/bits/stl_bvector.h: In member function ‘std::vector<bool, _Alloc>::size_type std::vector<bool, _Alloc>::max_size() const’:
/usr/include/c++/4.7/bits/stl_bvector.h:685:2: error: ‘max’ is not a member of ‘__gnu_cxx::__numeric_traits<long int>’

Hunting down the problem, I came across this piece of code in one of our own header files, which I assume is related to this problem:

#if defined(IRIX) | linux
signed  max(signed a, signed b);
long    max(long a, long b);
double  max(double a, double b);
float   max(float a, float b);
signed  min(signed a, signed b);
long    min(long a, long b);
double  min(double a, double b);
#define  __min min
#define  __max max
float   min(float a, float b);
#endif

and at lots of other places, I see calls to a __max() function with two arguments.

My educated guess is that I can replace all these calls to __max() with calls to std::max() and that I should include the <algorithm> header.

My two questions are:

  1. Is my educated guess correct?
  2. I assume the extra declarations and defines of min and max are some historical leftover. Does anyone know the history of it? Why was this code ever needed?
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

At the line 685 in bits/stl_bvector.h you have :

    __gnu_cxx::__numeric_traits<difference_type>::__max

Your ugly macro is replacing __max by max, hence the error.

You can effectively replace all your __max in your code by std::max, but just to be sure not to dismantle everything, you could first rename __max by __my__max, just to be sure (in your macro too). That way you will keep using the self-defined min/max functions.


Another solution would be to undef your macro before including stl headers and reenabling it after.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!