(risolto) Passare un vettore a switch

@stefa24 : OK ... trovato ... SI PUÒ FARE ... NON con il ANSI 'C, ma qui siamo su C++ e la cosa è ammessa con una differente parolina chiave NON 'const' ma 'constexpr' !

Esempio che compila: :grin:

constexpr long c[5] = {0,1,2,3,4};
long v = 0;

void setup() {
   // put your setup code here, to run once:
   switch (v) {
      case c[0]:

         break;
      case c[1]:

         break;
      case c[2]:

         break;
      default:

         break;
   }
}

void loop() {
   // put your main code here, to run repeatedly:

}

Guglielmo

P.S.: QUI il reference relativo all'attributo 'constexpr' :wink:

1 Like