Kindly let me know If there is way where I could use variable arguments inside a macro function and make the below macro code working.
To put it other way, Is there any way where I could use local variables in va_start.
typedef struct { char *p1; char *p2; char *p3; }Pointers; #define NULLCHECK_VR(num, ...) \ { \ va_list valist; \ int v_index; \ \ va_start(valist, num); \ \ for( v_index=0; v_index < num; v_index++) \ { \ if( NULL == va_arg(valist, void *)) \ { \ printf("NULL \n"); \ } \ else \ { \ printf("NOT NULL \n"); \ } \ } \ \ va_end(valist); \ } int main(void) { Pointers ptr; memset(&ptr, 0, sizeof(Pointers)); NULLCHECK_VR(3, ptr.p1, ptr.p2, ptr.p3) return (0); }
va_start(valist, num);is wrong as it applies to ..main.