加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c – 自我的typedef有效吗?

发布时间:2020-12-16 03:33:36 所属栏目:百科 来源:网络整理
导读:我遇到了一些具有以下内容的C代码: typedef Request Request; 这只是一个无操作或者这种typedef实际有效果,如果有,它有什么影响? 解决方法 您可以在7.1.3节中阅读与C 2003 ANSI ISO IEC 14882 2003的typedef说明符相关的所有规则.在7.1.3中,2)已经说过,如
我遇到了一些具有以下内容的C代码:
typedef Request Request;

这只是一个无操作或者这种typedef实际有效果,如果有,它有什么影响?

解决方法

您可以在7.1.3节中阅读与C 2003 ANSI ISO IEC 14882 2003的typedef说明符相关的所有规则.在7.1.3中,2)已经说过,如果名称已经引用了某种类型,则允许使用identity typedef.

这是合法的:

typedef int Request;
typedef Request Request; // Redefines "Request" with no effect

而事实并非如此:

typedef Request Request; // Illegal,first "Request" doesn't name a type.

该标准有一个与此相关的具体例子. C 2003,§7.1.3/ 2:

In a given non-class scope,a typedef specifier can be used to redefine the name of any type declared in
that scope to refer to the type to which it already refers. [Example:

typedef struct s { /* ... */ } s;
typedef int I;
typedef int I;
typedef I I;

end example]

在7.1.3中,3)已经说过禁止使用typedef将类型重新定义为别名到别名

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读