"Undeclared" 结构内声明的值的值

"Undeclared" value for value declared inside struct

我正在尝试 implement/understand 堆栈,但对于在本应代表堆栈的结构中声明的内容,我一直收到“未声明的值”

#define EmptyTOS ( -1 )
#define MinStackSize ( 5 )

typedef struct StackRecord *Stack;

struct StackRecord
{
    int Capacity;
    int TopOfStack;
    int *Array;
};

Stack CreateStack( int MaxElements )
{
    Stack S;    
    S = malloc( sizeof( struct StackRecord ) );
    S->Array = malloc( sizeof( int ) * MaxElements );
    S->Capacity = MaxElements;
    MakeEmpty( S );
    return S;
}

void MakeEmpty( Stack S ){
    S->TopOfStack = EmptyTOS;
}

void Push( int X, Stack S ){
    S->Array[++TopOfStack] = X;
}

int main(){

    Stack s1 = CreateStack(10);

    return 0;
}

如果我尝试只编译这个,我会得到:In function ‘Push’: error: ‘TopOfStack’ undeclared 我不明白为什么

因为TopOfStack没有申报

如果要访问S指向的对象的成员变量,应该写成S->TopOfStack.