3

§6.7.6.3 函数声明器

2) 唯一应该出现在参数声明中的存储类说明符是寄存器。

§6.7.6.3 函数声明器

13) 参数声明的声明说明符中的存储类说明符(如果存在)将被忽略,除非声明的参数是函数定义的参数类型列表的成员之一。

我已经这样声明和定义了......

int function(static int param)
{
    return param;
}

Visual Studio 发出警告。我的理解是,如果我们register在函数声明中使用作为参数类型,它应该在没有警告的情况下编译。除此之外register,它将忽略存储类并向用户抛出警告消息。我的理解正确吗?

谢谢

4

3 回答 3

7

我相信 6.7.6.3 是说存储类说明符在函数声明中被忽略;它说除非参数是函数定义的参数类型列表的一部分,否则它会被忽略。由于您显示的是函数定义,因此编译器在这里忽略这个无效的存储类说明符是不合适的。

于 2013-09-19T12:34:54.313 回答
1

AS 说 Visual Studio 不符合 c99/c11 标准。
这就是为什么这是作为警告抛出的原因。如果你用 gcc 编译 ..

您将到达error: storage class specified for parameter âparamâ函数声明和函数定义的位置

你只能使用 register 不应该使用其他的 比如 static,extern

于 2013-09-19T13:02:26.640 回答
1

First of all the compiler that you get with Visual Studio is not according to c99/c11 standard.

The function definition should not allow the use of storage class specifiers other than register. It should flag it as a bad use of storage class. As stated, VS compiler is not according to standard, it is throwing a warning message.

于 2013-09-19T12:37:52.507 回答