当我尝试引用结构体中的值时,为什么我会在 (' 之前得到预期的标识符

mis*_*ite 0 c struct pointers reference data-structures

我可以free(STRUCTPOINTER->thing1->thing2)

但我不能做free((*STRUCTPOINTER).(*thing1).thing2) ((令牌之前的预期标识符。对于(*thing1

我也不能做free((*STRUCTPOINTER).thing1.thing2)错误,(*temporary)->是一个指针,你的意思是使用'->'吗?

我习惯于编写代码并引用 (*this).format 中的内容。这对于我想做的事情来说可能吗?

Jon*_*ler 7

正如我在评论中(或多或少)指出的:

\n

如果您疯狂到不使用箭头表示法,\n您将需要使用:

\n
free((*(*ptr).thing1).thing2);\n
Run Code Online (Sandbox Code Playgroud)\n

抱歉,但我不喜欢按STRUCTPOINTER需要大声喊叫,尤其是因为它不是宏观的;我正在使用ptr

\n
    \n
  • *ptrptr是指向的结构
  • \n
  • (*ptr).thing1是结构体的成员,它是指向结构体的指针,所以需要
  • \n
  • *(*ptr).thing1取消引用该结构,并且
  • \n
  • (*(*ptr).thing1).thing2访问该元素
  • \n
\n

箭头表示法的发明是有充分理由的 \xe2\x80\x94 就是它!很难找到正确的替代方案。

\n