惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

T
The Exploit Database - CXSecurity.com
C
Cyber Attacks, Cyber Crime and Cyber Security
Forbes - Security
Forbes - Security
The Last Watchdog
The Last Watchdog
F
Full Disclosure
GbyAI
GbyAI
G
Google Developers Blog
Security Archives - TechRepublic
Security Archives - TechRepublic
阮一峰的网络日志
阮一峰的网络日志
T
The Blog of Author Tim Ferriss
C
Check Point Blog
S
Security @ Cisco Blogs
H
Help Net Security
N
News | PayPal Newsroom
D
DataBreaches.Net
L
LINUX DO - 最新话题
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
U
Unit 42
WordPress大学
WordPress大学
月光博客
月光博客
Security Latest
Security Latest
V
V2EX
Schneier on Security
Schneier on Security
美团技术团队
Y
Y Combinator Blog
G
GRAHAM CLULEY
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
S
Securelist
The Cloudflare Blog
Engineering at Meta
Engineering at Meta
P
Proofpoint News Feed
O
OpenAI News
Cisco Talos Blog
Cisco Talos Blog
Martin Fowler
Martin Fowler
N
News and Events Feed by Topic
小众软件
小众软件
S
Schneier on Security
Webroot Blog
Webroot Blog
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
V
Visual Studio Blog
T
Threatpost
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Scott Helme
Scott Helme
N
Netflix TechBlog - Medium
有赞技术团队
有赞技术团队
W
WeLiveSecurity
S
SegmentFault 最新的问题
Cloudbric
Cloudbric
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
M
MIT News - Artificial intelligence

博客园 - bullfinch

Notes of "The Unbridged Pentium 4" - Pentium 4 System Overview Notes of "The Unbridged Pentium 4" - Pentium 4 Road Map Notes of "The Unbridged Pentium 4" - Overview of the Processor Role Notes of "Pentium Processor System Architecture" - Pentium Signal Interface (part) Notes of "Pentium Processor System Architecture" - Mutiple Processors and the MESI Model Notes of "Pentium Processor System Architecture" - The Functional Units & Pentium Cache Overview AMD Opteron Architecture related Fedora Core 3 挂载FAT32分区以及中文显示和输入 摄像头设置事件 linux下安装HP NC6000无线网卡(HP W500) C#学习笔记(八) TreeView.AfterCheck和TreeNode.Checked赋值的问题 C#学习笔记(七) C#学习笔记(六) C#学习笔记(五) 图像中密集点群的定位 C#学习笔记(四) 中兴ZXDSL831立式蓝猫自动拨号+NAT+DHCP设置 C#学习笔记(三)
关于变参(zz)
bullfinch · 2005-01-26 · via 博客园 - bullfinch

This section contains an implementation of a minimal version of printf, to
show how to write a function that processes a variable-length argument list
in a portable way. Since we are mainly interested in the argument
processing, minprintf will process the format string and arguments but will
call the real printf to do the format conversions.
The proper declaration for printf is

   int printf(char *fmt, ...)

where the declaration ... means that the number and types of these
arguments may vary. The declaration ... can only appear at the end of an
argument list. Our minprintf is declared as

   void minprintf(char *fmt, ...)


since we will not return the character count that printf does.
The tricky bit is how minprintf walks along the argument list when the list
doesn't even have a name. The standard header <stdarg.h> contains a set of
macro definitions that define how to step through an argument list. The
implementation of this header will vary from machine to machine, but the
interface it presents is uniform.

The type va_list is used to declare a variable that will refer to each
argument in turn; in minprintf, this variable is called ap, for ``argument
pointer.'' The macro va_start initializes ap to point to the first unnamed
argument. It must be called once before ap is used. There must be at least
one named argument; the final named argument is used by va_start to get
started.

Each call of va_arg returns one argument and steps ap to the next; va_arg
uses a type name to determine what type to return and how big a step to
take. Finally, va_end does whatever cleanup is necessary. It must be called
before the program returns.

These properties form the basis of our simplified printf: