You are viewing a single comment's thread. Return to all comments →
Solution for any possible values of int... ** EDIT: Fixed INT_MAX and INT_MIN macros
#define INT_MIN (1 << ((sizeof(int) << 3)-1)) #define INT_MIN (~INT_MAX) int sum (int count,...) { va_list pArgs; int sum = 0; va_start(pArgs, count); while (count-- > 0) sum += va_arg(pArgs, int); va_end(pArgs); return sum; } int min(int count,...) { va_list pArgs; int curr = INT_MAX; va_start(pArgs, count); while (count-- > 0) { int val = va_arg(pArgs, int); if (val < curr) curr = val; } va_end(pArgs); return curr; } int max(int count,...) { va_list pArgs; int curr = INT_MIN; va_start(pArgs, count); while (count-- > 0) { int val = va_arg(pArgs, int); if (val > curr) curr = val; } va_end(pArgs); return curr; }
Seems like cookies are disabled on this browser, please enable them to open this website
Variadic functions in C
You are viewing a single comment's thread. Return to all comments →
Solution for any possible values of int... ** EDIT: Fixed INT_MAX and INT_MIN macros