I am trying to make a function with a variable number of arguments but only want two possible number of arguments for the function, either 7 or 11. I want to trigger a preprocessor error and quit compiling if there are not 7 or 11 arguments. I know it may seem silly to not just throw a printf with a warning during the program execution but this code is being written for a microcontoller and will not be running on a computer where it can give such a warning so I would like the compiler to catch this and warn me if possible.
void LCD_Attach(int num,...){
va_list valist;
va_start(valist, num);
if (num = 7)
{
//do something
}
else if (num = 11)
{
//do something else
}
else
{
#error LCD_Attach must have 7 or 11 arguments
}
va_end(valist);
}
I am aware this code will not work as written because when compiling the compiler always catches the #error and throws the error and the if else statement only works after compilation during execution. I cant use the preprocessor #if either because it cant read the variable num. There seems to be a clear divider between the preprocessor statements and the code that runs during execution. Am I approaching this problem completely wrong?