/* Varargs version */ #include #include #include "defs.h" /* Format of variable is variable(dummy, type, arg, type, arg ...) ANSI requires a single non-vararg argument, so I just made it a dummy 0. TYPE is a param_type that describes the following ARG. */ void variable(va_alist) va_dcl { va_list ap; int dummy; /* ANSI C requires one non-variable argument. */ va_start(ap); dummy = va_arg(ap, int); if (DUMMY != dummy) { printf(" FAILURE: First argument incorrect (%d)\n", dummy); exit(1); } for (;;) { switch(va_arg(ap, param_type)) /* Do this here, so macro used in instrumentation. */ { case PARAM_INT: check_int(va_arg(ap, int), Expected_int, ""); expect_truth(va_arg(ap, int) || Expected_int); /* Exercise instrumentation */ break; case PARAM_DOUBLE: check_double(va_arg(ap, double), Expected_double, ""); expect_truth(-5000 < va_arg(ap, double)); /* Exercise instrumentation */ break; case PARAM_STRING: check_string(va_arg(ap, char *), Expected_string, ""); expect_truth(va_arg(ap, char *)); /* Use up argument */ break; case PARAM_COMBO: { struct combo_t the_struct; the_struct = va_arg(ap, struct combo_t); check_int(the_struct.i, Expected_combo.i, "-in-structure"); check_string(the_struct.s, Expected_combo.s, "-in-structure"); check_double(the_struct.lf, Expected_combo.lf, "-in-structure"); expect_truth(va_arg(ap, struct combo_t).i ? 1 : 0); } break; case PARAM_END: va_end(ap); return; break; default: printf(" FAILURE: Type flag passed incorrectly.\n"); exit(1); /* To avoid error floods. */ break; } } /* Never reached. */ }