Are all compile warnings necessarily bad?

Every now and then I go over old code to see if I can do better. Revisiting one fairly extensive sketch that I wrote several years ago I noticed a single warning during compile, "switch condition has type bool"

I vaguely recall that this method saved me several lines of code and a variable or two but otherwise I don't know why I went this way other than thinking the color is either red (true) or it isn't (false).

In any event, the sketch works very well and this has never caused an issue however it raises the question, are all compile warnings necessarily a bad thing if you understand why?

// STARTING BOOLEANS

boolean red; // used to determine color, true = red, false = green

void setup()
{

}//end setup

void loop()
{

          red = !red; //switch color
          sirenFx(2, 500, 1000, 10 );  //system changing alert (type, lowFreq, highFreq, increment)
          switchLast = ledTimer; //note the time this switch occured

        }//end if
        else  switch (red) { //blink the currently active color
            //the case never changes if the programmed switch time is 0 (no switching)
            case true:
              blinkRed();
              break;

            case false:
              blinkGreen();
              break;
          }//end switch red
      }//end if

}// end loop

//FUNCTIONS

void blinkGreen(void)
{
  //last time color blinked
  digitalWrite(redLED, LOW); //trap the red
  if (ms - blinkLast > (ledState ? LED_ON : LED_OFF)) {
    digitalWrite(greenLED, ledState = ! ledState); //switch states
    blinkLast = ms;
  }
}//end blinkGreen

void blinkRed(void)
{
  // unsigned long blinkLast; //last time color blinked
  digitalWrite(greenLED, LOW); //trap the green
  if (ms - blinkLast > (ledState ? LED_ON : LED_OFF)) {
    digitalWrite(redLED, ledState = ! ledState);
    blinkLast = ms;
  }
}//end blinkRed

The compiler is giving you great advice. For a colour choice like this, you should create an enum for RED/GREEN and switch on that. The performance gain on being able to use '!' to toggle it, is minimal, and the action is slightly confusing to the reader.

C doesn't strongly enforce the difference between what you can do, and what you should do.

Also in this particular case, you should allow for adding colours in future, which you can't do with two choices.

Compiler warnings are bad even if you understand/explain them away. If you know the cause, deal with it, even if you just cast something so that the compilation is clean.

The obvious problem is that if you let it ride, eventually, something serious will crop up and you will ignore it among a flood of other messages.

I think what the compiler is saying that a 'bool' having only 2 possible states is in a way if/else, switch/case is a more efficient way of if/else if where the part of the compare that is in the switch() is only loaded into the compare register once, and the compared to all cases, which should save progmem and time. but if there is only 2 options, then if/else only does a compare once where a switch/case does 2 compares. I figure usually it should be optimized out but there is no guarantee. You should test if/else to see if that saves progmem.

Ok guess that answers that. I did as suggested and replaced it with an else if.

Thanks for the input, much appreciated.