I have function in C with 3 params. I want to call that function with pre-defined values. Is there any solution?
My idea which does not work.
#define PRE_DEFINED_MACRO (10, 15 , true)
void myFunc(uint8_t temp, uint32_t value, bool valid)
{
....
}
....
//call the function like that
myFunc(PRE_DEFINED_MACRO);
>Solution :
Your macro already includes parentheses, so when this …
myFunc(PRE_DEFINED_MACRO);
… is expanded, the result is:
myFunc((10, 15 , true));
You could do this instead:
myFunc PRE_DEFINED_MACRO;
I find that pretty confusing, however. Personally, I would prefer to remove the parentheses from the macro’s replacement text:
#define MYFUNC_ARGS 10, 15 , true
// ...
myFunc(MYFUNC_ARGS);
That makes it much clearer that the call to myFunc() is, in fact, a function call. The choice of macro name also makes the intended purpose of the macro much clearer.