typedef结构体对自身的影响是什么? [英] What is the effect of typedef'ing a struct to itself?

查看:171
本文介绍了typedef结构体对自身的影响是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看到这个代码写在一个API的顶部:

I've seen this code written at the top of an API:

typedef struct SYSTEM SYSTEM;

类型 SYSTEM 以前未定义。有谁知道这是什么?编译器认为 SYSTEM 之后是什么?

The type SYSTEM was previously undefined. Does anyone know what this does? What does the compiler think a SYSTEM after this line?

感谢您的答案!我的问题是SYSTEM之前没有在文件中定义,所以我不知道它是什么。例如,该行将自行编译,但 struct SYSTEM 未在任何位置定义。

Thanks for the answers! My question is that SYSTEM was not previously defined in the file, so I have no idea what it is. For example, that line will compile by itself, but struct SYSTEM was not defined anywhere.

推荐答案

它允许你在C中使用名称 SYSTEM ,而不是使用 struct SYSTEM
typedef 创建一个同义词 SYSTEM struct SYSTEM

It allows you in C to use the name SYSTEM instead of using struct SYSTEM. The typedef creates a synonym SYSTEM to struct SYSTEM.

struct SYSTEM 未声明的情况下,声明还声明 struct SYSTEM 作为一个不完整的类型,如下面的声明: struct SYSTEM;

In your case as struct SYSTEM is not declared, the declaration also declares struct SYSTEM as an incomplete type like in this declaration: struct SYSTEM;.

然后可以在另一个翻译单元中声明完整的对象类型 struct SYSTEM

The complete object type struct SYSTEM can then be declared in another translation unit.

这篇关于typedef结构体对自身的影响是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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