在C中,如果我声明一个这样的结构:
static struct thing {
int number;
};
Run Code Online (Sandbox Code Playgroud)
并编译它(在这种情况下使用gcc),编译器打印此警告:
警告:此声明中忽略'static'
[-Wmissing-声明]
为什么是这样?
我使结构静态的意图是远离thing全局命名空间,以便另一个文件可以在需要时声明它自己thing.
您无法定义存储而无需定义实际对象.
static struct thing {
int number;
}obj1,obj2;
Run Code Online (Sandbox Code Playgroud)
没关系,并且:
struct thing {
int number;
};
static struct thing x,y;
Run Code Online (Sandbox Code Playgroud)