c - extern 是编写不是定义的声明的唯一方法吗?

标签 c

得出变量声明的唯一类型是“外部声明”的结论是否理智?

已知下面的代码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/

相关文章:

c - 右箭头等于右箭头

c - dlsym(RTLD_NEXT, "msgctl") 不返回默认版本

c - 实现一个新的strcpy函数重新定义库函数strcpy?

c - 二维数组问题

c - 动态分配的矩阵不允许输入

c - 为什么这个涉及指数的 C 计算会产生错误的答案?

c - 理解 C 中的双空指针

c - 如何在Mac OS X的C程序中包含hdf5头文件?

c - 数据类型介绍

c - 两个指针的逻辑与循环直到程序中断