Struct x vs x_t in C

In my last class of operating systems, we have a bunch of objects defined as such:

typedef struct someobj {
  ... stuff ...
} someobj_t;

I know this is great.

The question is, sometimes in this code support structures were called struct someobj *some, and sometimes how someobj_t *some. Is there an actual / useful reason to refer to structures in these two different ways, or is it just a stylistic difference?

+5
source share
5 answers

Assuming we ask about the following code (there isn’t typedefin the question that I am writing, but I assume that it should have been there):

typedef struct someobj {
    // content
} someobj_t;

someobj someobj_t. , , :

typedef struct someobj {
    struct someobj* next;
    // cannot say someobj_t* yet - typedef not complete
} someobj_t;

// and from now on, both struct someobj and`someobj_t are equivalent
+5

, typedef , typedef , _t. POSIX POSIX. , .

typedef , , , .

+6

, ( ) someobj. , :

typedef struct {
  ...
} someobj_t;

, , (, ). :

typedef struct someobj_t {
  ...
} someobj_t;
+2

, :

typedef struct someobj
{
    /* ... */
} someobj_t;

; " C" - ( struct , ), someobj_t.

, , typedef, , (, ++, #,...), struct. struct typedef ed.

, ; , typedef _t , , _t.

typedef "" ; , typedef ed. typedef "" , /, , "" , typedef ed structure .

, MIDL ; . Raymond Chen .

Last but not least, you can only forward ads with the name of a real structure; and if you don’t have a structure name (but only typedef), you won’t be able to make forwarded ads.

+2
source

I think you mean

typedef struct someobj {
 ... stuff ...
} someobj_t;

This allows you to use someobj_t as a type instead struct someobj. Both notations are equivalent.

+1
source

All Articles