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

515
Visualizações
What does "Comparing constant with boolean expression is always true" warning mean?

What does this warning mean (i and j are not constants):

I have been trying to Google this but it does not give me any results.

warning: comparison of constant 10 with boolean expression is always true [-Wtautological-constant-out-of-range-compare]

 if ((0<=i<=10)&&(0<=j<=10)){

In my program, i and j are not constant values and they do change.

over 4 years ago · Santiago Trujillo
3 Respostas
Responde à pergunta

0

In C, chaining of relational operators like this are not valid design. Thus,

 (0<=i<=10)

is not doing what you think it should be doing. it is getting evaluated as

((0<=i) <= 10 )

which is basically either

  • 0 < = 10, producing 1 (considered TRUE value)
  • 1 < = 10, also producing 1 (considered TRUE value)

sadly, both of which are way out than the expected path.

Solution: you need to break down your condtion check like

 (0 <= i) && ( i<=10)
over 4 years ago · Santiago Trujillo Relatório

0

I believe you need to understand what's going on in your statement at a deeper level.

0<=i is a boolean expression, it will become true or false. The result of that expression is then compared with 10.

So you end up with true <= 10 or false <= 10.

I think you meant to write

if ( ( 0 <= i ) && ( i <= 10 ) )

You cannot connect clauses together the way you did.

over 4 years ago · Santiago Trujillo Relatório

0

The other answers have already explained the core problem. You can use:

if ( ( ( 0 <= i) && (i <= 10)) && ( ( 0 <= i) && (i <= 10)) ) 

to resolve your problem.

My recommendation will be to wrap that logic in a function.

int isInRange(int x, int lower, int upper)
{
   return (lower <= x && x <= upper);
}

and use

if ( isInRange(i, 0, 10) && isInRange(j, 0, 10) )
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