va_start/va_arg/va_end/va_list

在看UEP的时候,作者自定义了几个error_handle函数

#include <stdarg.h>     /* ISO C variable aruments */
void    err_dump(const char *, ...);        /* {App misc_source} */
void    err_msg(const char *, ...);
void    err_quit(const char *, ...);
void    err_exit(int, const char *, ...);
void    err_ret(const char *, ...);
void    err_sys(const char *, ...);

其中好几个地方都有用到va_start va_arg va_end 这几个宏函数,查了一些资料之后将总结记录下来。
首先声明:

测试环境是 GCC:4.8.2
          GDB:7.7.1
          kernel:3.13.0-36-generic

这几个宏函数主要是针对C语言里的可变参数列表做处理。

参考(还是en好理解):

vsnprintf()


write formatted output to a character array, up to a maximum number of character (varags)

Synopsis:
        #include <stdarg.h>
        #include <stdio.h>
        int vsnprintf( char*   buf,
                       size_t   count,
                       const char* format,
                       va_list  arg );
Arguments:
    buf
        A pointer to the buffer where you want to function to store the formatted string.
    count
        The maximum number of characters to store in the buffer, including a terminating null character.
    format
        A string that specifies the format of the output. The formatting string determines what additional arguments you need to provide. For more information, see printf().
    arg
        A variable-argument list of the additional arguments, which you must have initialized with the va_start() macro.
Library:
    libc
Description:
    The vsnprintf() function formats data under control of the format control string and stores the result in buf. The maximum number of characters to store, including a terminating null character, is specified by count.
    The vsnprintf() function is a “varargs” version of snprintf().
Returns:
    The number of characters that would have been written into the array, not counting the terminating null character
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值