将一个va_list作为参数传递给另一个 [英] Passing one va_list as a parameter to another

查看:1449
本文介绍了将一个va_list作为参数传递给另一个的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用fastcgi库创建一个应用程序,他们的打印方法有点冗长。我试图将他们的fprintf函数包装在我自己的方法中:

I'm creating an application using the fastcgi library, and their method of printing is a little verbose. I'm trying to wrap their fprintf function in my own method:

我想转动


FCGX_FPrintF(out,char * fmt,...);

FCGX_FPrintF(out, char* fmt, ...);


write(char * strFormat,...);

write(char* strFormat, ...);

发现了va_list的魔力,但找不到一个简单的方法来传递va_list值到他们的fprintf函数。有办法做到这一点吗?我知道vsprintf和vprintf存在,所以它必须比我想象的更难。

I've found the magic of va_list but can't find an easy way to pass va_list values into their fprintf function. Is there a way to do this? I know vsprintf and vprintf exist so it must be harder than I imagine it is.

如果所有其他失败,我只是重载一个写函数

If all else fails, I'll just overload a write function

推荐答案

您必须在Fast CGI库中找到 vfprintf()的类比。至少有一个合理的可能性,有一个;实现 FCGX_FPrintF()的简单方法是:

You would have to find the analogue of vfprintf() in the Fast CGI library. It is at least moderately plausible that there is one; the easy way to implement FCGX_FPrintF() is:

void FCGX_FPrintF(FILE *out, char *fmt, ...)
{
    va_list args;
    va_start(args, fmt);
    FCGX_VFPrintF(out, fmt, args);
    va_end(args);
}

所以很有可能函数存在;您需要检查它是否正式公开。

So it is highly probable that the function exists; you will need to check whether it is exposed officially or not.

快速访问 Fast CGI网站揭示了FCGX前缀由fgciapp.h头中声明的函数使用,并且依次包含:

A quick visit to the Fast CGI web site reveals that the FCGX prefix is used by functions declared in the fgciapp.h header, and that in turn contains:

/*
 *----------------------------------------------------------------------
 *
 * FCGX_FPrintF, FCGX_VFPrintF --
 *
 *      Performs printf-style output formatting and writes the results
 *      to the output stream.
 *
 * Results:
 *      number of bytes written for normal return,
 *      EOF (-1) if an error occurred.
 *
 *----------------------------------------------------------------------
 */
DLLAPI int FCGX_FPrintF(FCGX_Stream *stream, const char *format, ...);

DLLAPI int FCGX_VFPrintF(FCGX_Stream *stream, const char *format, va_list arg);

所以,接口已经完成了。

So, there's the function with the interface completed.

这篇关于将一个va_list作为参数传递给另一个的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆