Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Typedef of a structure name to a pointer

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);
}
like image 235
user1467764 Avatar asked Sep 11 '25 21:09

user1467764


1 Answers

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.

like image 181
CodeClown42 Avatar answered Sep 13 '25 11:09

CodeClown42