This is the contemporary (and incorrect) way to declare structures and structure pointers. The compiler swallows it only because this is the old-time way that structures were declared.
Code:
struct stackNode {
int data;
struct stackNode *nextPtr;
};
typedef struct stackNode StackNode;
typedef StackNode *StackNodePtr;
The above is a "pascalized" _forward_ declaration method. It gives 'stackNode' form without substance until it is typedef'd as a new (that is "non-homogenous", or "extrinsic") type.
The reason you have 'typedef struct stackNode StackNode; is so that you tell the compiler that the amorphous forward declaration of 'stackNode' is to be considered and referred to by the 'StackNode' type.
The reason you have 'typedef 'StackNode *StackNodePtr' is to create a type of pointer variable that refers to the new type.
Here is the modern, correct way to create both the declaration and the typedef--
Code:
typedef struct stackNode
{
int data;
struct stackNode *nextPtr;
}StackNode, *StackNodePtr;
The reason you give the forward declaration ('stackNode') in this structure at all, is because it references itself, so the compiler must be able to locate the forward declaration already on the symbol table in order to resolve the self-reference.
Also, please give thought that whenever you create linked lists, you always put the self-referencing pointer as the _first_ member in the structure. It's a good habit. That way, if you ever have to change the size or orientation of the structure (say, you update software), that pointer can _always_ be found because it's at the structure's starting address. It makes 'backwards compatibility' much easier.
For example:
Code:
typedef struct stackNode
{
struct stackNode *nextPtr;
int data;
}StackNode, *StackNodePtr;
Enjoy.