Weird compiler error

This is driving me nuts. Can anyone tell me why the following code won’t compile?

ftoa (mb, res, 1) ;
#ifdef NEX
   Pressmb.setText (res) 
#else
   setCursor (18,11) ;
   lcd.print(res);
   delay (100) ;
   lcd.println();
   delay(100);
#endif
   
// Pressure tendency display: 
#ifdef NEX
   if (P0 > P2)  // **** Compiler error on this line ****
      PresTend.setText ("+") ;  // rising pressure
   if (P0 == P2)
      PresTend.setText (" ") ; // needed for correct spacing  
      ftoa (P0 - P2, res, 2) ;
   PresTend.setText (res) ; // show the change
   switch (Ptend)
     {
      case (1):
         PresTend.setText ("/ ") ;
      break ;
      case (2):
         PresTend.setText ("\\") ;
      break ;
      case (3):
         PresTend.setText ("_ ") ;
      break ;
      case (4):
         PresTend.setText ("v ") ;
      break ;
      case (5):
         PresTend.setText ("^ ") ;
      break ; 
      case (6):
         PresTend.setText ("_/") ;
      break ; 
      case (7):
         PresTend.setText ("\\_") ;
      break ; 
      case (8):
         PresTend.setText ("/^") ;
      break ; 
      case (9):
         PresTend.setText ("^\\") ; 
      break ;
      default:
      PresTend.setText ("? ") ; // should never happen
     } // end switch
#else // for Sparkfun LCD
   setCursor (8,12) ;
   if (P0 > P2)
      lcd.print ("+") ;  // rising pressure
   if (P0 == P2)
      lcd.print (" ") ; // needed for correct spacing  
   lcd.print (P0 - P2) ; // show the change
   delay (100) ;
   switch (Ptend)
     {
      case (1):
         lcd.print ("/ ") ;
      break ;
      case (2):
        {
         // Back slash hack - col. no. 13 line no. 12
         lcd.print ("  ") ; // clear the previous line
         lcd.drawLine (12*6, 12*8, 12*6+4, 12*8+6, 1) ;
        }
      break ;
      case (3):
         lcd.print ("_ ") ;
      break ;
      case (4):
         lcd.print ("v ") ;
      break ;
      case (5):
         lcd.print ("^ ") ;
      break ; 
      case (6):
         lcd.print ("_/") ;
      break ; 
      case (7):
       {
         lcd.print ("  ") ; // clear the previous trend line
         setCursor (14,12) ;
         lcd.drawLine (12*6, 12*8, 12*6+4, 12*8+6, 1) ;
         lcd.print ("_") ;
        }
      break ; 
      case (8):
         lcd.print ("/^") ;
      break ; 
      case (9):
        {
         lcd.print ("^") ; // clear the previous line
         lcd.drawLine (12*6, 12*8, 12*6+4, 12*8+6, 1) ; // "^\"
        }
      break ;
      default:
      lcd.print ("? ") ; // should never happen
     } // end switch
   delay (100) ;
  #endif

This gives this error:

/src/weatherlcd1.cpp:1209:8: error: expected ';' before 'if'
               if (P0 > P2)

But if I comment out the first #ifdef block at the top of this code

    ftoa (mb, res, 1) ;
  /*   #ifdef NEX
        Pressmb.setText (res) 
     #else
        setCursor (18,11) ;
        lcd.print(res);
        delay (100) ;
        lcd.println();
        delay(100);
     #endif
  */

  // Pressure tendency display: 
      #ifdef NEX
         if (P0 > P2)  // Now no compiler error on this line
            PresTend.setText ("+") ;  // rising pressure

it compiles fine. I have literally been staring at this for hours now.

The message pretty clearly states it wants a semicolon at the end of this line :wink:
Which is the last line before the respective if() statement due to the conditional compiling instructions.

2 Likes

Doh! Yes. Of course. Obviously. (Why didn’t I see that?) Works fine now. Sigh.

Thanks :slight_smile: