Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

248
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda