Difficulty: Easy
Correct Answer: False
Explanation:
Introduction / Context:
This concept check clarifies what va_list
actually is. Many learners assume it is a simple array or pointer. In reality, va_list
is an implementation-defined type that may be a pointer, a struct, an array type, or something else depending on the platform and ABI.
Given Data / Assumptions:
with the macros va_start
, va_arg
, and va_end
.
Concept / Approach:
The C standard defines va_list
abstractly. Code must treat it as opaque and manipulate it only via the standard macros. Assuming it is an “array” is incorrect and leads to non-portable code. On some platforms it may be a single pointer; on others, a small structure holding register saves and stack pointers, or even an array type. The only portable way to use it is through the macros and, when needed, va_copy
to duplicate it.
Step-by-Step Solution:
Declare: va_list ap;
Initialize: va_start(ap, last_named_param);
Iterate: value = va_arg(ap, type);
Finish: va_end(ap);
Verification / Alternative check:
Inspect headers for different compilers; you will observe varying typedefs for va_list
. This confirms it is not universally an array.
Why Other Options Are Wrong:
“True only on GCC/MSVC” is misleading; each implementation may choose a different representation, and user code should not depend on any particular one.
Common Pitfalls:
Taking the address of a va_list
and assuming pointer arithmetic works portably, or copying it by assignment without va_copy
where required.
Final Answer:
False
Discussion & Comments