在 C 中,如果我像这样声明一个结构:
static struct thing {
int number;
};
并编译它(在这种情况下使用 gcc),编译器打印出这个警告:
warning: 'static' ignored on this declaration
[-Wmissing-declarations]
这是为什么?
我将结构设为静态的目的是将 thing
保留在全局命名空间之外,以便另一个文件可以根据需要声明自己的 thing
。
最佳答案
您不能在不定义实际对象的情况下定义存储。
static struct thing {
int number;
}obj1,obj2;
没问题,并且:
struct thing {
int number;
};
static struct thing x,y;
关于C 编译器忽略 'static' 的结构声明,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52087025/