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

显然在Unix v6中没有定义实例的Struct

发布时间:2020-12-15 21:44:52 所属栏目:安全 来源:网络整理
导读:我正在阅读带有Lion的书的Unix版本6的代码.其中一个头文件(param.h,可以访问 here)定义了以下结构: /*struct to access integers*//*single integer */struct { int integ; };/*in bytes*/struct { char lobyte; char hibyte; }; 这些结构似乎没有定义任何
我正在阅读带有Lion的书的Unix版本6的代码.其中一个头文件(param.h,可以访问 here)定义了以下结构:

/*struct to access integers*/

/*single integer */
struct { int integ; };

/*in bytes*/
struct { char lobyte; char hibyte; };

这些结构似乎没有定义任何实例,它们也没有命名,因此可以在以后使用.有谁知道它们的用途是什么?

谢谢

解决方法

如果有人将整个文件包含在联合声明中,则允许他们访问不同的部分.

它会是这样的:

union{
   #include <param.h>
  } myparam;

  myparam.integ = 0xDEAD;
  assert(myparam.lobyte == 0xAD)
  assert(myparam.hibyte == 0xDE)

(取决于建筑的字节顺序……)

所以看了一下,似乎在旧版本的C中,你不需要声明联合;所有struct / union成员只有一个名称空间,只是转换为可以在任何变量上使用的字节偏移量.我能找到的最好的一点就是:
http://docs.sun.com/source/806-3567/compat.html
描述ISO之前的Sun C:
?

Allows struct,union,and arithmetic types using member selection operators (‘.’,‘->’) to work on members of other struct(s) or unions.

(编辑:李大同)

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

    推荐文章
      热点阅读