how can I avoid the use of #if in a polymorphic print macro
问题 Let's try to run the following code: #include <stdio.h> #define MY_MACRO1(isArray,y) do { \ if(isArray) \ printf("%d", y[0]); \ else \ printf("%d", y); \ }while(0) int main() { int a = 38; int b[]={42}; MY_MACRO1(0,a); return 0; } it returns the error: main.c: In function ‘main’: main.c:12:39: error: subscripted value is neither array nor pointer nor vector printf("%d", y[0]); \ Ok, so we would need a #if statement to run y[0] only if the variable is an array: #define MY_MACRO2(isArray,y) do