[How to Solve] dereferencing pointer to incomplete type

Solution:

Code situation

Initial condition: the chain stack already exists, and there is at least one element
typedef struct
{
	ElemType data;
	struct LinkedStackNode* next;
}LinkedStackNode, *Linknode;

//
/*
Initial condition: the chain stack already exists, and there is at least one element
*/
int StackTop(Linknode top, int* x)
{
	if(top->data == 0)
		return -1;
	*x = top->next->data;
	return 1;
}

Analyze problems

Dereference pointers of incomplete types

The meaning here is that there are incomplete pointers. The structure and pointer belong to reference types, and the internal definition of the structure is complete. Therefore, only the structure itself is incomplete, that is:

/
//typedef struct Modify to:
typedef struct LinkedStackNode
{
	ElemType data;
	struct LinkedStackNode* next;
}LinkedStackNode, *Linknode;

{
	ElemType data;
	struct LinkedStackNode* next;
}LinkedStackNode, *Linknode;

//
/*
Initial condition: the chain stack already exists, and there is at least one element
*/
int StackTop(Linknode top, int* x)
{
	if(top->data == 0)
		return -1;
	*x = top->next->data;
	return 1;
}

 

Similar Posts: