简体   繁体   English

C中的typedef结构AA

[英]typedef struct A A in C

Does this mean anything: 这意味着什么:

typedef struct spBone spBone;
struct spBone {
...
}

I found the above in a header of a .c file. 我在.c文件的标题中找到了以上内容。 What could be the side-purpose of assigning a non-alternative name to a struct? 非替代名称分配给结构的副作用可能是什么?

First, remember that C and C++ are different languages. 首先,请记住C和C ++是不同的语言。 C++ is rooted in C, but went in some very different directions. C ++扎根于C,但发展方向却截然不同。 This is one of them. 这就是其中之一。

When declaring or defining a variable of type struct in C, one must always use the keyword struct . 在C语言中声明或定义struct类型的变量时,必须始终使用关键字struct For example 例如

struct spBone myspBone;

is required. 是必须的。 Why this is required likely made a lot of sense back in the 1970s. 为什么需要这样做可能在1970年代很有道理。

However, the programmer is establishing spBone as an alias to struct spBone so that they can use the alias and 但是,程序员正在将spBone建立为别名以struct spBone以便他们可以使用别名和

spBone myspBone;

as you can in C++. 就像在C ++中一样。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM