得出变量声明的唯一类型是“外部声明”的结论是否理智?
已知下面的代码define(不是declare)x
,因为它为变量x
分配了内存>(韩国第 4 章)。不过,通常情况下,我们通常只会说我们正在声明 x
(但不会初始化它)。
int x; // <-- definition NOT declaration
我能找到的唯一声明示例是使用关键字extern
:
extern int x;
extern int a[];
除了extern declaration还有其他变量声明情况吗?
最佳答案
定义是带有存储的声明。从标准:
6.7 Declarations 3/ A declaration specifies the interpretation and attributes of a set of identifiers. A definition of an identifier is a declaration for that identifier that:
— for an object, causes storage to be reserved for that object;
— for a function, includes the function body;119)
— for an enumeration constant, is the (only) declaration of the identifier;
— for a typedef name, is the first (or only) declaration of the identifier.
然后函数原型(prototype)是一个声明,如果用于前向声明,则可能没有限定extern
。一个
有关详细信息,请阅读标准第 6.7 节。
关于c - extern 是编写不是定义的声明的唯一方法吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35805620/