GCC不再实现< varargs.h>. [英] GCC no longer implements <varargs.h>
本文介绍了GCC不再实现< varargs.h>.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我必须将此代码片段从varargs.h更改为stdarg.h,但我不知道确切如何:
I have to change this code fragment from varargs.h to stdarg.h, but I do not know exactly how to:
#ifndef lint
int ll_log (va_alist)
va_dcl
{
int event, result;
LLog *lp;
va_list ap;
va_start (ap);
lp = va_arg (ap, LLog *);
event = va_arg (ap, int);
result = _ll_log (lp, event, ap);
va_end (ap);
return result;
}
当我尝试构建它时,编译器会说:
When I try build this, compiler says:
error "GCC no longer implements <varargs.h>."
error "Revise your code to use <stdarg.h>."
我需要编译和运行的程序有一些类似的片段,我需要知道如何更改它们.如果您能写一些例子,我会很满足的.
The program, which I need to compile and run, has a few similar fragments and I need to know how to change them. If you can write some example, I'll be content.
推荐答案
< varargs.h>
是标准的C标头;请使用< stdarg.h>
.区别:
<varargs.h>
is a pre-standard C header; use <stdarg.h>
instead. The differences:
- 该函数必须至少包含一个命名参数.
- 该函数必须是原型(使用省略号终止符).
-
va_start
宏的工作方式不同:它带有两个参数,第一个是要初始化的va_list
,第二个是最后一个命名参数的名称.
- The function must take at least one named argument.
- The function must be prototyped (using the ellipsis terminator).
- The
va_start
macro works differently: it takes two arguments, the first being theva_list
to be initialized and the second the name of the last named argument.
示例:
int ll_log (LLog *llog, ...) {
int event, result;
LLog *lp;
va_list ap;
va_start (ap, llog);
lp = llog;
event = va_arg (ap, int);
result = _ll_log (lp, event, ap);
va_end (ap);
return result;
}
关于 va_start
:gcc忽略了第二个参数,但没有给出正确的参数是不可移植的.
Regarding va_start
: gcc ignores the second argument, but not giving the correct one is not portable.
这篇关于GCC不再实现< varargs.h>.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文