There are 2 unrealated problems here:
Definition of the initial structure should look like:
struct Scommand {
int a;
struct Scommand *next;
}
Without that you are trying to insert the whole structure into itself. This makes type definition recursive and this not allowed.
Second point. C and C++ have a concept of forward declaration:
struct Scmd *someCommand;
It might be surprising, but this line makes 2 things:
- Creates forward declaration for
Scmd
structure in the names table.
- Defines the variable
someCommand
.
In spite of the fact that this line looks like definition of the variable, in reality there are 2 definitions here. Now returning back to your code:
struct Scommand *commandList=0;
struct SCommand *thisCommand;
thisCommand = commandList;
The names of the structures are different because all names in C are case sensitive. The first one is already defined. The second one SCommand
is defined in place. This is independent structure and it is not related to your original structure. This is the reason for the error. I agree that in this particular case the error is not very self explanatory. But well, it may appear in other cases where it might sound more appropriate.