为什么没有ANSI C有命名空间? [英] Why doesn't ANSI C have namespaces?

查看:213
本文介绍了为什么没有ANSI C有命名空间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有命名空间似乎像没有脑子的大多数语言。但据我所知,ANSI C不支持它。为什么不?任何计划,包括在未来的标准?

Having namespaces seems like no-brainer for most languages. But as far as I can tell, ANSI C doesn't support it. Why not? Any plans to include it in a future standard?

推荐答案

ç确实有命名空间。一为结构标记,一个用于其他类型。考虑下面的定义:

C does have namespaces. One for structure tags, and one for other types. Consider the following definition:

struct foo
{
    int a;
};

typedef struct bar
{
    int a;
} foo;

第一种具有的标签的美孚,后者是由与一个typedef Foo类型。仍然没有名称争食发生。这是因为结构变量和类型(内置类型和Typedef的类型),住在不同的命名空间。

The first one has tag foo, and the later is made into type foo with a typedef. Still no name-clashing happens. This is because structure tags and types (built-in types and typedef'ed types) live in separate namespaces.

什么C不允许是创建的新的的意志命名空间。下标准化之前这是在语言视为重要的,并且加入的命名空间也将威胁向后兼容,因为它需要名称重整工作的权利。我想这可以归结由于技术问题,不是哲学。

What C doesn't allow is to create new namespace by will. C was standardized before this was deemed important in a language, and adding namespaces would also threaten backwards-compatibility, because it requires name mangling to work right. I think this can be attributed due to technicalities, not philosophy.

编辑:
JeremyP幸好纠正我,并提到我错过了命名空间。有用于标签和结构/联合成员以及命名空间。

JeremyP fortunately corrected me and mentioned the namespaces I missed. There are namespaces for labels and for struct/union members as well.

这篇关于为什么没有ANSI C有命名空间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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