vendredi 8 février 2019

Alternative to a large group of if-statements?

I have a set of If Statements (a lot of them, around 40), and they each check an input for an embedded board. For some reason, running through the group of statements is really slow.

#define INPUT_X INPUT_ARRAY[0] // input 1 corresponds to the first array slot and so on

if ( INPUT_X != 0){
   output_x |= some_bit // this logic could change
}

The code is structured like above and from 1 to 40. They are not if-else-if statements though. I would use a switch, but from my knowledge a switch only covers 1 case at a time, and multiple inputs could be on. Is there a faster way of covering all the inputs without using so many ifs?

Aucun commentaire:

Enregistrer un commentaire