Pergunta

I had struct point {(...)}; defined. But with ANSI standards 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 {};?

Foi útil?

Solução

You can do:

typedef struct Point { ... } MyPoint;

and then use both kinds of declarations:

struct Point p1;
MyPoint p2;

Outras dicas

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.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top