Chinaunix首页 | 论坛 | 博客
  • 博客访问: 226189
  • 博文数量: 80
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 781
  • 用 户 组: 普通用户
  • 注册时间: 2014-11-08 10:41
个人简介

爱莉清

文章分类

全部博文(80)

文章存档

2018年(1)

2017年(18)

2016年(49)

2015年(7)

2014年(5)

我的朋友

分类: 嵌入式

2016-10-20 09:08:57

函数参数的传递原理
  函数参数是以数据结构:栈的形式存取,从右至左入栈。

点击(此处)折叠或打开

  1. VOID Nguhyw_printf(const char *fmt, ...)
  2. {
  3.     va_list args;
  4.     int length;
  5.     char log_buf[CFG_CONSOLEBUF_SIZE];

  6.     va_start(args, fmt);
  7.     /* the return value of vsnprintf is the number of bytes that would be
  8.      * written to buffer had if the size of the buffer been sufficiently
  9.      * large excluding the terminating null byte. If the output string
  10.      * would be larger than the log_buf, we have to adjust the output
  11.      * length. */
  12.     length = vsnprintf(log_buf, sizeof(log_buf) - 1, fmt, args);
  13.     if (length > CFG_CONSOLEBUF_SIZE - 1)
  14.         length = CFG_CONSOLEBUF_SIZE - 1;

  15.     uart_write(log_buf, length);
  16.     va_end(args);
  17. }















阅读(2529) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~