I know there is a C++ version of this question, however I'm using standard typedefs not templates.
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.
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.
So I tried to test out the following code:
#include <stdio.h>
int
main()
{
int i;
scanf("%i", &i);
typedef short test;
if(i == 1)
typedef short sample;
else
typedef int sample;
return 0;
}
And got got the following compiler errors:
dt.c: In function ‘main’:
dt.c:12:5: error: expected expression before ‘typedef’
dt.c:14:5: error: expected expression before ‘typedef’
Does this mean that runtime conditional typedefs in C are not possible?
[Open-ended question:] If not, how would you guys handle something like this?