gpt4 book ai didi

c - 指向指针的结构名称的 Typedef

转载 作者:太空宇宙 更新时间:2023-11-03 23:49:31 24 4
gpt4 key购买 nike

所以A是在别处定义的结构体。您可以忽略此处定义变量的顺序。在这里,当我使用“B”定义一个新变量时,到底发生了什么?它是否创建了一个变量,该变量是指向 A 类型结构的指针?我想尽可能详细地解释 'typedef struct A *B;' 时会发生什么。遇到了。谢谢。

typedef struct A  *B;

typedef struct {
B pd_ctx;
} C;

static inline B convert (B handle)
{
C *ctx;

ctx = (C *)handle;

return (ctx->pd_ctx);
}

最佳答案

typedef struct A  *B;

when I use 'B' to define a new variable, what exactly is happening? Is it creating a variable which is a pointer to a structure of type A?

是的。如果你这样看可能会更清楚:

typedef struct A*  B;

星号放在哪里是风格问题,就像参数和声明一样。

在这种情况下 B 不是指针,它是指针类型。

关于c - 指向指针的结构名称的 Typedef,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23978771/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com