The Definition of Type

The notation struct student this_student is a bit clumsy. We think of this_student as having the type of struct student , but all the other types we have are just a single word. (There are modifiers that we can apply making the whole think more than a single word, though.) In order to give these new types we create the same status as the built-in types in the appearance of the code, we have the typedef declaration. We could, for example, have the declaration:
typedef struct student STUDENT;

and now we can declare a variable to be of type STUDENT as in
STUDENT this_student;

(We find a wide variety of typographic styles used for these new types. Some programmers make them all upper case as we've done here, others make them all lower case and still others make them mixed case.)

We can also dispense with the structure tag altogether as in

typedef struct {
   char name[30];
   char address[60];
   int extension;
   int grad_year;
   float gpa;

With a declaration like this, we can do the same type of variable declaration as we did before.

It turns out that we can also that we can use typedef to create synonyms for any types in our program, not just the structures. For example, we frequently find lines like:

#define TRUE 1
#define FALSE 0
typedef char BOOLEAN;

in a program. Here, we're creating a new type called BOOLEAN that we'll be using to store values that are either TRUE or FALSE . So we could declare a variable like:
BOOLEAN is_valid;

and then set it like:
is_valid = TRUE;

Since we've defined the values for TRUE and FALSE to match what the conditional expressions in C do, we could then perform a test like:

Write a declaration creating a new type which is named THINGY and is the same thing as the union whose tag is stuff .