摘要: 1 /* 2 * stdarg.h 3 * 4 * Provides facilities for stepping through a list of function arguments of 5 * an unknown number and type. 6 * 7 * NOTE: Gcc should provide stdarg.h, and I believe their version will work 8 * with crtdll. If necessary I think you can replace this with th... 阅读全文
posted @ 2012-09-17 17:41 ziyoudefeng 阅读(3287) 评论(0) 推荐(0) 编辑
摘要: 可变参数函数主要是利用了三个宏,va_start, va_arg, va_end和一个类型va_list。先写个小例子,然后再说明这三个宏的含义。例:计算指定数量的值的平均值 1 #include <stdarg.h> 2 3 float 4 average(int n_val, ...) 5 { 6 va_list arg; // 等价于char *arg; 7 int count; 8 float sum = 0; 9 10 va_start(arg, n_val); // arg = &n_val + 4 (假设这里int长度是4个字节)11 ... 阅读全文
posted @ 2012-09-17 17:38 ziyoudefeng 阅读(905) 评论(5) 推荐(0) 编辑