Hello,
I'm trying to modify some code I made to be more convenient to test. The program has several initial conditions which are defined at the beginning, such as vector length, memory offset, and type. Each time I compile the code, I modify the initial conditions to do a specific test, so I want to make the code require as few manual changes as possible. There is also a variable for initial value of the variable, but depending on the type, this must be different. So far I haven't found anything that would work.
Code:#define N_INIT 0 #define NTIMES 1000 #define OFFSET_INIT 0 #define OFFSET_STEP 0 #define THREAD_INIT 128 #define THREAD_STEP 0 #define ITER 700 /* settings for test */ static int N = N_INIT; // initial vector length float _type; // used for type of array element static typeof(_type) elem_init = 2.f; // if _type is float ********************** //static typeof(_type) elem_init = 2.f; // if _type is double //static typeof(_type) elem_init = 'a'; // if _type is char static int OFFSET = OFFSET_INIT; static int THREADS = THREAD_INIT; static int OPERATION = OPERATION_SET;
On the line with the string of asterisks, I would like to test the type of _type at runtime so I can choose to initialize it as 2.f if it is a float or double and 'a' if it is a char.
Essentially, I would like to be able to do something like:
if( typeof(_type) == (float) ) elem_init = 2.f;
elseif( typeof(_type) == (char) ) elem_init = 'a';
Is anything like this possible in C?
thanks,
nads