对struct的双指针进行故障诊断

时间:2018-03-24 19:11:27

标签: c pointers

我有一个struct元素和一个指向该结构的双指针

结构声明:

struct stackItem
{
    int item;
    struct stackItem *itemBelow;
};

功能定义

void popItem(struct stackItem **ppTop)

{
    if (*ppTop == NULL)
    {
        printf("The stack is empty, there are no items to pop \n");
    }
    else
    {
        struct stackItem *itemToBeFreed = *ppTop;
        printf("Item that was popped is %d\n", (*ppTop)->item)
        *ppTop = (*ppTop)->itemBelow; // This line fails to compile
        free(itemToBeFreed);
    }

}

我得到的编译错误是:

stack.c:109:9: error: invalid operands to binary expression ('int' and 'struct stackItem **')
        *ppTop = (*ppTop)->itemBelow;

根据我的理解,equlas符号两侧的表达式求值为指向struct stackItem的指针 - 我缺少什么?

提前致谢!

0 个答案:

没有答案