Hello,
If I have this definition in a header file:
typedef struct A
{
int test;
} B;
What exactly is A and what is B ?
`A' is a "struct tag," something that distinguishes one particular
kind of struct from other kinds. The combination `struct A' names the
type of that particular kind of struct, so you can use that name in
other contexts like `struct A instance;' to declare a variable of that
struct type or `struct A *pointer;' to declare a variable that points
to objects of that type. `A' by itself means nothing in C; the rules
in C++ are different.
`B' is an alias for the type `struct A', and can be used wherever
`struct A' could. So `B instance;' declares a variable of the struct
type, and `B *pointer;' declares a variable that can point to it. `B'
and `struct A' are interchangeable.
What does it mean when I declare like this:
typedef struct A
{
int test;
};
It means you declare `struct A' and `A' with the meanings as above.
Then you start to declare an alias for `struct A' but never provide the
alias' name. I'm not sure the Standard requires a diagnostic for this
vacuous attempt at an alias, but compilers are likely to warn about it
in any case. It's a lot like writing `typedef float;' and never giving
the name that you want to use as an alias for `float'.
And what does it mean when I declare like this:
typedef struct
{
int test;
} B;
Again you declare a struct type, but this one has no name of its
own: There is no way to complete `struct ???' to name the type of
this struct. However, you also declare `B' as an alias for that
anonymous struct type, so you can still write `B instance;' and
`B *pointer;'. So, `B' is an alias for a type that has no true name
of its own, but `B' will serve as a perfectly good substitute.