title: Runtime conditional typedef in C
body: <p>I know there is a C++ version of this question, however I'm using standard typedefs not templates.</p>
  
  <p>I've written a program that works with 16-bit wav files. It does this by loading each sample into a short. The program then performs arithmetic on the short.</p>
  
  <p>I'm now modifying the program so it can with with both 16- and 32-bit wavs. I was hoping to do a conditional typedef, i.e. using short for 16-bit and int for 32-bit. But then I realised that the compiler probably would not compile the code if it did not know what the type of a variable is beforehand.</p>
  
  <p>So I tried to test out the following code:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  
  int
  main()
  {
    int i;
    scanf("%i", &amp;i);
  
    typedef short test;
  
    if(i == 1)
      typedef short sample;
    else 
      typedef int sample;
  
    return 0;
  }
  </code></pre>
  
  <p>And got got the following compiler errors:</p>
  
  <pre><code>dt.c: In function ‘main’:
  dt.c:12:5: error: expected expression before ‘typedef’
  dt.c:14:5: error: expected expression before ‘typedef’
  </code></pre>
  
  <p>Does this mean that runtime conditional typedefs in C are not possible?</p>
  
  <p>[Open-ended question:] If not, how would you guys handle something like this?</p>