c - stdarg.h中定义的函数va_start(va_list ap,parmN),为什么标识符parmN不能用寄存器存储类声明?

标签 c

头文件 stdarg.h 中定义的函数 va_start() 有两个参数 va_list ap 和 parmN,这里 parmN 是命名函数定义中可变参数列表中最右边参数的标识符(就在 , . ..)。这里我不明白为什么说它不能用寄存器存储类声明。

最佳答案

首先,va_start is a macro, not a function .

The va_start and va_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 the register storage-class specifier.

关于c - stdarg.h中定义的函数va_start(va_list ap,parmN),为什么标识符parmN不能用寄存器存储类声明?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30674004/

相关文章:

c - 在读取结构体中的数据之前检测其是否已损坏

c - 用于教育目的的小型 c 编译器

c++ - C/C++ 中的非 GPL 开源潜在狄利克雷分配实现/库

c - printf 连续打印

c - 如何在 C 中修改共享内存(shmget/shmat)?

c - 32 位 TIFF 图像呈白色且与 RAW 不同

c - 关于 C 中的嵌套函数

c - fscanf 和换行符

c - fopen 的替代品,害怕从字符串中读取?

C Strtok 段错误