Difficulty: Easy
Correct Answer: Fixed parameters must come before the ellipsis; they cannot occur at the end
Explanation:
Introduction / Context:
The language requires that the ellipsis ... be the final token in the parameter list. Therefore, any fixed (named) parameters must precede it. This guarantees that va_start can be given the correct last named parameter and that the compiler can generate the appropriate calling sequence.
Given Data / Assumptions:
Concept / Approach:
Named parameters define the boundary between fixed and variadic arguments. Placing a named parameter after the ellipsis would make it impossible for the callee to find how many and what types of arguments were passed, and it is not allowed by the grammar.
Step-by-Step Solution:
Define all fixed parameters first (e.g., fmt).Append ... to indicate the start of unnamed arguments.Inside the function, use va_start(ap, fmt) to enter the unnamed region and process with va_arg.
Verification / Alternative check:
Trying to compile f(..., int x) yields a diagnostic; printf-style signatures demonstrate the correct order.
Why Other Options Are Wrong:
The compiler cannot infer parameter order. Constness and target ABI do not change the rule.
Common Pitfalls:
Believing you can add “optional trailing named parameters” after the ellipsis; that is not the model C uses.
Final Answer:
Fixed parameters must come before the ellipsis; they cannot occur at the end
Discussion & Comments