java typedef struct,C和H文件中的Typedef和Struct

既然你问这个语言“为什么”的确切原因,我假设你需要一些精确的参考.如果你发现那个学究,只需跳过笔记……

它的作用是因为两件事:

>所有指向结构类型的指针都具有相同的表示形式(请注意,就标准C而言,并非所有指针类型都是如此).[1]因此,编译器有足够的信息来为指针到结构类型的所有用法生成适当的代码.

>标签命名空间(struct,enum,union)确实与所有翻译单元兼容.[2]因此,两个结构(即使一个未完全定义,即它缺少成员声明)是同一个.

(顺便说一句,#import是非标准的.)

[1]根据n1256§6.2.5.27:

All pointers to structure types shall have the same representation and alignment requirements as each other. Pointers to other types need not have the same representation or alignment requirements.

[2]根据n1256§6.2.7.1:

two structure, union, or enumerated types declared in separate translation units are compatible if their tags and members satisfy the following requirements: If one is declared with a tag, the other shall be declared with the same tag. If both are complete types, then the following additional requirements apply: [does not concern us].

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值