头文件 stdarg.h 中定义的函数 va_start() 有两个参数 va_list ap 和 parmN,这里 parmN 是命名函数定义中可变参数列表中最右边参数的标识符(就在 , . ..)。这里我不明白为什么说它不能用寄存器存储类声明。
最佳答案
首先,va_start
is a macro, not a function .
The
va_start
andva_arg
macros described in this subclause shall be implemented as macros, not functions.
现在,有了这个,C99 rationale回答你的问题:
The restrictions on the declaration of the
parmN
parameter follow from the intent to allow this kind of implementation, as applying the&
operator to a parameter name might not produce the intended result if the parameter’s declaration did not meet these restrictions.
总而言之,标准委员会希望给予 C 标准库使用 &
运算符实现可变参数的自由,如果 parmN
要有 register
存储持续时间,那么标准库可能会由于违反 section 6.5.3.2, paragraph 1 而导致未定义的行为。 :
The operand of the unary
&
operator shall be either a function designator, the result of a[]
or unary*
operator, or an lvalue that designates an object that is not a bit-field and is not declared with theregister
storage-class specifier.
关于c - stdarg.h中定义的函数va_start(va_list ap,parmN),为什么标识符parmN不能用寄存器存储类声明?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30674004/