Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

250
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda