c - 声明一个同时具有寄存器和静态存储类的变量

标签 c gcc static c89 register-allocation

(ANSI-C 89) 您好,是否可以同时声明一个变量 staticregister ?每当我尝试这样做时,我都会收到一条错误提示:multiple storage classes in declaration specifiers

这是代码:

#include <stdio.h>

void f1(static int i);
int main()
{
    static register int i;

    i = 5;
    f1(i);
}

void f1(static int i)
{
    static int y =6;
    y+=1;
    printf("\n Y=%d \n",y);
}

和那个

最佳答案

registerstatic都是存储类说明符,最多只能指定一个存储类说明符。

来自 C11 标准 ISO/IEC 9899:2011:

6.7.1 Storage-class specifiers

Syntax

  1.      storage-class-specifier:
              typedef
              extern
              static
              _Thread_local
              auto
              register

Constraints

  1. At most, one storage-class specifier may be given in the declaration specifiers in a declaration, except that _Thread_local may appear with static or extern.120)

120)See ‘‘future language directions’’ (6.11.5).

关于c - 声明一个同时具有寄存器和静态存储类的变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34694979/

相关文章:

c - 宏连接中的有效预处理器标记

c - 面向 C 开发人员的 .vimrc

c++ - 在 C++ 中,单例(静态实例)一旦程序退出就会被销毁的原因是什么

c++ - C 和 C++ 中的结构内部定义差异

c - 仅 header 库不使用 header 保护。如何在其他头文件中使用该库?

c - 未定义对 `__time32` ncurses 的引用

c++ - 类模板静态成员初始化两次

java - 同名JAVA类中的静态和非静态方法

c - 使用心跳信号在c中进行线程监控

c++ - 2D OpenGL 场景因大量重叠形状而变慢