简体   繁体   中英

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. 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++ is rooted in C, but went in some very different directions. This is one of them.

When declaring or defining a variable of type struct in C, one must always use the keyword struct . For example

struct spBone myspBone;

is required. Why this is required likely made a lot of sense back in the 1970s.

However, the programmer is establishing spBone as an alias to struct spBone so that they can use the alias and

spBone myspBone;

as you can in C++.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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