Question's Background:
void dash(int *n, char c) is to draw characters c separated by '+'.
Parameter n is an array of ints, e.g. {1, 3, 2} and '-' for c should give "+-+---+--+", which works fine.
To use dash I do {int f={1, 3, 2}; dash(f, '-');}, which makes the construct copy&pastable.
The question itself:
To avoid copy&pasting I wanted to do #define F(X, Y) {int f=X; dash(f, Y);},
resulting in a nicely usable F({1, 3, 2}, '-').
Unfortunately the compiler complains about F getting 4 (array's length + 1) arguments instead of 2.
So how can you give {1, 3, 2} as parameter to a macro?
Variadic macros are a feature of C99.
#define F(Y,...) dash((int[]){__VA_ARGS__},Y)
So how can you give {1, 3, 2} as parameter to a macro?
F('-',1,3,2);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With