您的位置:首页 > 数据库 > Oracle

Oracle SQL*PLUS中使用变量

2009-08-31 10:44 495 查看
In C and C++, a function can have optional function arguments. For example,

 

int printf
(const char *template, ...

)

 

How about we wrapp this function? For example,

int printError(const char* template, ...) {
// additional logic
// an invocation of printf
// additional logic
}

 

 In fact, there is no way to passing the optional arguments of printError to printf. The solution is to use va_list. For this example, we can can use vprintf.

int printError(const char* template, ...) {
// additional logic
va_list ap;
va_start(ap, template);
vprintf(template, ap);
va_end(ap);
// additional logic
}

 
If we want to define some API with optional arguments, we use optional arguments in the exposed API. But for the internal implementation, we should use va_list since va_list can be passed from function definition to function defintion. 

 

For details, you can refer to 12.12.9 Variable Arguments Output Functions
in The GNU C Library Reference Manual
.

 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: