struct X { };
Create a new type. So you can declare this new type
struct X myvar = {...}
or
struct X *myvar = malloc(sizeof *myvar);
typdef is used to indicate type
typedef enum { false, true } boolean; boolean b = true;
So you renamed enum to boolean.
So when you write
typedef struct X {
You rename the struct X structure to X. When I said rename, it is more a different name.
Tips, you can simply write:
typedef struct {
But if you need a field with the same type (for example, in a linked list), you had to specify the name of your structure
typedef struct X { X *next; struct X *next; } X;
Hope this helps :)
Edit: As Kate Thompson said, typdef is for creating an alias :)
source share