4
typedef struct st {
    double d ;
    struct st *n ;
} st, *List ;

On this part:

} st, *List ;

What is this second "st"? Is it an object created (why does it have the same name as the type)? I don't understand the "*List". Does it use typedef to say that a "List" is a pointer to an "st"? Thank you.

SadSeven
  • 1,247
  • 1
  • 13
  • 20
  • It take me less than one minute to figure out your answer because this question is a double with this one http://stackoverflow.com/questions/1543713/c-typedef-of-pointer-to-structure. Next time, consider searching one google before posting. – Luc DUZAN May 02 '14 at 13:29

4 Answers4

4

The part

typedef struct st {...} st;

creates a new symbol st that can be used to declare instances of struct st without the keyword struct. You can read this article for more information - it has some examples.

The second declaration *List creates a pointer type to struct st so you can declare a pointer to the structure without having to write struct st*.

typedef essentially creates an alias that can be used in place of the original type.

xxbbcc
  • 16,930
  • 5
  • 50
  • 83
2

The first st is part of struct st and creates a named struct. The second st is part of typedef … st and creates a type as an alias for struct st. The * List creates a type List as a pointer to struct st.

ckruse
  • 9,642
  • 1
  • 25
  • 25
2

typedef lets you define multiple type aliases. For example, you can do this:

typedef int Number, *NumberPtr;

This defines Number to be an alias for int, and NumberPtr to be an alias for int*.

Your declaration does the same, except it uses struct st instead of an int. In other words, it defines two type names - st for the struct st, and List for struct st*.

This lets you write

st s;
List p;

instead of

struct st s;
struct st *p;
Sergey Kalinichenko
  • 714,442
  • 84
  • 1,110
  • 1,523
1

This does three things: The first is it defines a struct called struct st that contains a double and a pointer to another struct st. This first task could be accomplished on its own like so:

struct st {
    double d ;
    struct st *n ;
};

The typedef is doing two more things. It is defining st to be struct st and also defining List to be struct st *. A more simple example of this 2x typedef is something like:

typedef int Integer, *PointerToInteger;
turbulencetoo
  • 3,447
  • 1
  • 27
  • 50