Ç - 限制范围结构 [英] C - Limit struct Scope

查看:114
本文介绍了Ç - 限制范围结构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个.c文件这样的结构:

I am having this structure in a .c file:

struct entry {
    int position;
    int length;
    struct entry *node;
};

现在,我怎么能限制这种结构的范围的布局的主机文件,这样使用相同的名称时,新结构的布局在另一个文件的,我不明白重新定义的错误?

Now, how can I limit the scope of this structure layout to the host file, so that when using the same name for a new structure layout in another file, I don't get 'redefinition' error?

我尝试过的结构的使用的静态的,但似乎没有用(我也没有意义)。 BTW,<一个href=\"http://stackoverflow.com/questions/7059800/why-do-structure-definitions-have-internal-linkage\">this问题似乎没有有效的给我,因为我得到复制时,重新定义的错误的 stuct条目的跨越链接文件(使用MinGW的)。

I tried using static before struct, but it seems of no use (I also doesn't make sense). BTW, this question doesn't seem valid to me, as that I get 'redefinition' error when duplicating stuct entry across linked files (using MinGW).

---编辑---结果
对于那些谁想要知道更多:<一href=\"http://stackoverflow.com/questions/612328/difference-between-struct-and-typedef-struct-in-c\">here,和这里

--- Edit ---
For those who want to know more: here, and here.

推荐答案

您不会得到重新定义错误。类型是本地的翻译单元的,并没有任何知名度。只有函数和数据对象都有知名度。

You won't get a redefinition error. Types are local to translation units, and don't have any visibility. Only functions and data objects have visibility.

如果你得到重新定义错误,必须使其在同一个翻译单元结束了在页眉或其它包含文件中使用该名称。

If you're getting a redefinition error, you must be using that name in a header or other included file so it ends up in the same translation unit.

这篇关于Ç - 限制范围结构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆