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

推荐订阅源

Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
The GitHub Blog
The GitHub Blog
B
Blog
小众软件
小众软件
Jina AI
Jina AI
WordPress大学
WordPress大学
V
V2EX
MongoDB | Blog
MongoDB | Blog
Blog — PlanetScale
Blog — PlanetScale
P
Proofpoint News Feed
Y
Y Combinator Blog
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
人人都是产品经理
人人都是产品经理
Microsoft Azure Blog
Microsoft Azure Blog
aimingoo的专栏
aimingoo的专栏
C
CERT Recently Published Vulnerability Notes
C
Cisco Blogs
Project Zero
Project Zero
云风的 BLOG
云风的 BLOG
K
Kaspersky official blog
Google DeepMind News
Google DeepMind News
宝玉的分享
宝玉的分享
T
Threat Research - Cisco Blogs
S
Securelist
V
Vulnerabilities – Threatpost
雷峰网
雷峰网
F
Fortinet All Blogs
D
DataBreaches.Net
I
Intezer
D
Docker
The Hacker News
The Hacker News
The Last Watchdog
The Last Watchdog
SecWiki News
SecWiki News
MyScale Blog
MyScale Blog
腾讯CDC
博客园_首页
Martin Fowler
Martin Fowler
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
Application and Cybersecurity Blog
Application and Cybersecurity Blog
H
Help Net Security
GbyAI
GbyAI
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
L
Lohrmann on Cybersecurity
I
InfoQ
H
Hacker News: Front Page
T
Threatpost
Stack Overflow Blog
Stack Overflow Blog
博客园 - 叶小钗
T
Troy Hunt's Blog
Microsoft Security Blog
Microsoft Security Blog

博客园 - 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: