title: better way to check if variable has enum value in C
body: <p>my question is related to appearance of the code and how is it doing in terms of performance.</p>
  
  <p>let's say i have an enum:</p>
  
  <pre><code>typedef enum {
     THIS_IS_A_VALUE1 = 65,
     THIS_IS_A_VALUE2 = 10,
     THIS_IS_A_VALUE3 = 45,
     THIS_IS_A_VALUE4 = 5,
     THIS_IS_A_VALUE5 = 7
  } I_AM_AN_ENUM;
  </code></pre>
  
  <p>and i want to check whether a certain variable contains one of the values in the enum:
  i thought about three ways to do it:</p>
  
  <p>1.</p>
  
  <pre><code>int val;
  if(val != THIS_IS_A_VALUE1 &amp;&amp; val != THIS_IS_A_VALUE2 &amp;&amp; val != THIS_IS_A_VALUE3...)
  {
  // val is different than all values
  // do something
  }
  </code></pre>
  
  <p>2.</p>
  
  <pre><code>if(val != THIS_IS_A_VALUE1)
  {
  // keep blank
  }
  else if(val != THIS_IS_A_VALUE2)
  {
  // keep blank
  }
  else if(val != THIS_IS_A_VALUE3)
  {
  // keep blank
  }....
  else
  {
  // val is different than all values
  // do something
  }
  </code></pre>
  
  <p>3.</p>
  
  <pre><code>switch(val)
  {
  case THIS_IS_A_VALUE1:
  case THIS_IS_A_VALUE2:
  case THIS_IS_A_VALUE3:
  ..
  ..
  default:
  // val is different than all values
  // do something
  }
  </code></pre>
  
  <p>to be honest, i find 2 and 3 ugly, especially when there are a lot of values in the enum.
  the first way can also be pretty ugly but better then the others, though using a lot of &amp;&amp; can reduce from the performance from my understanding.</p>
  
  <p>so to summarize: readability and performance are very important to me,
  and i'm really unsure which of the options is the best,
  or maybe there are other ways to do it?</p>
  
  <p>thanks.</p>
  
  <p>EDIT: i forgot to mention that the values are <em>not</em> sequential, that's the case and I can't really change it.</p>