Can't assign struct variable in header file

Hi guys.
I have a header file including a structure like this:

typedef struct
{
    int index = -1;
    stack_node *head;
} stack;

But when compiling with cc it shows error at the assignment line (int index = -1):

error: expected �:', �,', �;', �}' or �__attribute__' before �=' token

should I add an initialization function to initialize variables?

The problem is that you can not initialize members in a structure definition.

1 Like