Working with void pointers
I have a struct
Code:
typedef struct
{
void *l_var;
void *r_var;
}EXPR;
EXPR expr;
I initialize it
Code:
expr.l_var = &motor_rt_params[0].position;
expr.r_var = &motor_rt_params[1].position;
Now I want to operate with the values
Code:
result = *(expr.l_var) – *( expr.r_var);
I get an exception
Error[Pe041]: expression must have arithmetic or pointer type
I have to cast it to a known type
Code:
result = *((int32_t *) expr.l_var) - *((int32_t *)expr.r_var);
But not all variables is 32 bit? there is 16, 8 bit.
How can cast it to an appropriate type in run time?