【发布时间】:2012-11-14 23:19:59
【问题描述】:
我正在尝试从Batctl 2011.2.0 编译bat-hosts.c。但是,这是 CLANG 3.1 编译器从 Android NDK rev 发出的错误消息。 8c:
bat-hosts.c:41:1: 错误:函数声明器中的存储类说明符无效
我在同一个 NDK 版本中从 GCC 4.6 收到类似的错误消息。
第 41 行内容如下:
static struct hashtable_t *host_hash = NULL;
这个指向hashtable_t 结构的指针(在hash.h 中定义)在任何函数之外被声明为静态,并在声明时指向NULL,我认为这是有效的。
我尝试在 std 选项设置为 gnu11、c11、gnu1x、c1x 和 c99 的情况下运行 GCC/CLANG。
我的问题是:
为什么编译器将此指针识别为函数声明?
提前致谢
编辑:
hashtable_t 结构定义:
struct hashtable_t {
struct element_t **table; /* the hashtable itself, with the buckets */
int elements; /* number of elements registered */
int size; /* size of hashtable */
hashdata_compare_cb compare; /* callback to a compare function.
* should compare 2 element datas for their keys,
* return 0 if same and not 0 if not same */
hashdata_choose_cb choose; /* the hashfunction, should return an index based
* on the key in the data of the first argument
* and the size the second */
};
第二次编辑: 感谢大家的帮助。在按照@JonathanLeffler 的建议创建了一个 SSCCE 之后,我发现这个问题与一个额外的库有关,我忘记了我包括在内。很抱歉浪费了您的时间:-/
@JonathanLeffler,如果您愿意,可以发布回复,我会将其标记为答案。
【问题讨论】:
-
hashtable_t的确切定义是什么? -
@bames53 我添加了
hashtable_t定义。 -
无法在普通Linux系统上重现。但该行是此处文件中的第 38 行。
-
你能启用编译器警告吗(gcc 中的
-Wall,据我所知,clang 中类似)? -
hashdata_compare_db和hashdata_choose_cb的 typedef 是什么?那里有存储类吗?基本上,您应该向我们展示一个重现问题的 SSCCE (Short, Self-Contained, Correct Example)。应包括所有(但仅)必要的标题。尽可能只使用标准标题。通常,创建 SSCCE 的过程无论如何都会帮助您解决问题。
标签: android c gcc android-ndk clang