#define A_1 {2,1124,124110,2,0,20,5121,0,21241,10}
#define SFY(macro) #macro
void func(char* s, int i) {
printf("%d %s", i, s);
}
int main (void) {
int a[10] = A_1;
func(SFY(A_1), 2);
}
My desired output of this would be:
2 {2,1124,124110,2,0,20,5121,0,21241,10}
How can I stringify a macro like this?
You need to add one more layer of indirection in order to expand the macro (and since it contains commas, you must go variadic):
#define A_1 {2,1124,124110,2,0,20,5121,0,21241,10}
#define SFY_2(...) #__VA_ARGS__
#define SFY(macro) SFY_2(macro)
void func(char* s, int i) {
printf("%d %s", i, s);
}
int main (void) {
int a[10] = A_1;
func(SFY(A_1), 2);
}
[Live example]
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