什么时候需要包含varargs.h文件? 这个是标准库文件么?一般要处理可变长参数都用stdargs.h,如下代码没有
什么时候需要包含<varargs.h>文件? 这个是标准库文件么?
一般要处理可变长参数都用stdargs.h,如下代码没有问题:
C/C++ code#include<stdarg.h>void f(const char* fmt,...){ va_list ap; va_start(ap,fmt); short s=va_arg(ap,short); char c=va_arg(ap,char); int i=va_arg(ap,int); printf("%d,%c,%d\n",s,c,i); va_end(ap);}int main(void){ f("abc",(short)20,'a',10); return 0;}
但是我发现如果把stdarg.h改成了varargs.h就不行了,varargs.h里面的定义和stdarg.h的还不太一样。
问题: 什么时候我们需要用到varargs.h这个用法呢?
[解决办法]不是标准。好像和实现的平台有关系
[解决办法]COMPATIBILITY
These macros are not compatible with the historic macros they replace.
A backward compatible version can be found in the include file
varargs.h.
BUGS
Unlike the varargs macros, the stdarg macros do not permit programmers
to code a function with no fixed arguments. This problem generates
work mainly when converting varargs code to stdarg code, but it also
creates difficulties for variadic functions that wish to pass all of
their arguments on to a function that takes a va_list argument, such as
vfprintf(3).