For example, in the reference:
type va_arg (va_list ap, type)
Does ap
stand for argument pointer? Something else?
That's actually an easy question to answer.
ap
stands for argument pointer .
From The C Programming Language , Second Edition, Brian W. Kernighan and Dennis M. Ritchie:
7.3 Variable-length Argument Lists
[...] 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"
ap
stands for Argument Pointer . In fact, it is sometimes abbreviated as arg_ptr
:
type va_arg(
va_list arg_ptr,
type
);
type
- Type of argument to be retrieved.arg_ptr
- Pointer to the list of arguments.
That's actually a difficult question to answer.
See ouah's answer ; the phrase "argument pointer" is mentioned in K&R2.
The <stdarg.h>
header was introduced by the ANSI C standard in 1989. The ANSI C Rationale doesn't show any examples, and doesn't use the name ap
or arg_ptr
. The standard itself (the latest draft is here uses the name ap
in examples, but doesn't explain it.
I haven't been able to find an explanation of the name ap
. It's plausible that it originally stood for "argument pointer", but it's also important to note that the type va_list
is not (necessarily) a pointer type. In gcc, for example, it's defined as __builtin_va_list
, a type that's implemented directly by the compiler. (It happens to have a size of 24 bytes on my system, but that's not particularly useful information).
Bottom line: The name ap
is the conventional name for a va_list
object, for no particular reason that we need to care about.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.