Typedef of a structure name to a pointer
c, pointers, structure, typedef
Solution
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?
Yes. It may be clearer if you look at it like this:
typedef struct A* B;
Where the asterisk goes is a matter of style, as with parameters and declarations.
In this case B is not a pointer, it's a pointer type.
Problem
So A is a structure defined elsewhere. You may ignore the order in which the variables are defined here. Here, 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? I would like as detailed an explanation as possible for what happens when 'typedef struct A *B;' is encountered. Thanks. ``` 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); } ```