Is it possible to use function pointer in switch case?
<p>I'm using a function pointer based state machine.
I need a function to check for different stats. The amount of functions is pretty massive. Therefore I would like to not use if else if else... chains. I would like to use a swithc case statement:
I used the following code:</p>

<pre><code>    switch (my_state_func)
    {
       case &amp;idle_state_func:
       case NULL:
          //...
          break;
       case &amp;failed_func:
          break;
       default:
          break;
    }
</code></pre>

<p>Now the compiler tells me I can't use pointer in switch case</p>

<p>Is there a way to fix this? I tried integer casting of the pointer.
This generates the error:</p>

<p>label doesn't reduce to an integer constant</p>

<pre><code>case (int)&amp;idle_func:
</code></pre>

<p>Is there maybe a macro or somthing? Logically it should be possible since every function point is a integer. </p>

<p>Thanks for help.</p>