简体   繁体   中英

C90 and typedef

I had struct point {(...)}; defined. But with C90 it seems I have to do it with typedef. How do I do this correctly? typedef struct point {} point; ? typedef struct {} point; ? typedef struct point {}; ?

You can do:

typedef struct Point { ... } MyPoint;

and then use both kinds of declarations:

struct Point p1;
MyPoint p2;

Both of these are correct:

typedef struct point { /* ... */ } point;
typedef struct { /* ... */ } point;

The first version defines struct point and then defines point as an alias for it, while the second defines point as an alias for an anonymous struct.

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