【发布时间】:2017-08-24 12:27:58
【问题描述】:
我有两个文件,main.c 和 hash.c
在 hash.c 中,我只有一个名为 hashtable 的空哈希表和一些函数(不是主函数)
在 main.c 中,我有 main() 函数和 #include "hash.h"
我的问题是,如果在 main.c 中,我从 hash.c 中调用一个函数,例如:hash_add("strawberry", 3),它在 hash.c 的哈希表中添加一个键及其元素(称为 @987654324 @),
如果我在 main.c 中执行 extern hash * hashtable,我的 3 个草莓会在哈希表中吗?还是我的哈希表是空的?
(我的想法是,当我调用hash_add("strawberry", 3) 时,只要我在函数范围内,我的 3 个草莓就在哈希表中)
谢谢
【问题讨论】:
-
如果你在 hash.c 中有
hash *hastable;,你必须在你想使用变量的每个其他文件中写extern hash *hashtable;。
标签: c file structure share global