Originally Posted by
laserlight
You would cast to a pointer to whatever is the underlying type, in this case it would be the type of &motor_rt_params[0].position. It is also always safe to cast to a pointer to a character type to compute the difference in bytes, but is that what you're trying to do here?
By the way, I don't recommend EXPR as a struct alias. It is common convention in C for fully uppercase names to be used for macros or constants. A capitalised name like Expr might be a suitable alternative.
But how I decide what type to cast? It is generic function
Code:
void SCRIPT_Process(void *l_var, void *r_var, uint32_t oper)
{
int32_t res;
switch (oper)
{
case OP_PLUS:
res = *((??? *) l_var) + *((??? *)r_var);
break;
case OP_MINUS:
res = *((??? *) l_var) - *((??? *)r_var);
break;
}
}
How can I know what type the argument points and what type to cast?
Code:
SCRIPT_Process(expr.l_var , expr.r_var , OP_PLUS);