【发布时间】:2014-10-08 13:10:17
【问题描述】:
我想知道下面的 C sn-p 是否正确,其中 f 的定义没有重复 f 是 static 链接,是正确的:
static int f(int);
int f(int x) { return x; }
Clang 不会发出任何警告。我阅读了 C11 标准的第 6.7.1 条,但没有找到问题的答案。
可以想象更多类似的问题,例如下面的 t1.c 和 t2.c,如果答案足够笼统以适用于其中一些问题,那就太好了,但我只是真的很担心关于上面的第一个例子。
~ $ cat t1.c
static int f(int);
int f(int);
int f(int x) { return x; }
~ $ clang -c -std=c99 -pedantic t1.c
~ $ nm t1.o
warning: /Applications/Xcode.app/…/bin/nm: no name list
~ $ cat t2.c
int f(int);
static int f(int);
int f(int x) { return x; }
~ $ clang -c -std=c99 -pedantic t2.c
t2.c:3:12: error: static declaration of 'f' follows non-static declaration
static int f(int);
^
t2.c:1:5: note: previous declaration is here
int f(int);
^
1 error generated.
【问题讨论】:
标签: c language-lawyer c11