coding style - Proper typedef syntax in C -


short question
there proper or preferred way to use typedefs of structs , enums in c?

background
have been working on code base has had several people / companies working on , have come across different implementations of typedefs. according wikipedia appear have same function. guess i'm trying understand if there subtile differences or gotchas between them. same usages , question applies typedefing enum.

// tend use if need create // alias outside defining module.  typedef struct obj obj_t; struct obj {     uint8 val; };  // started use format alias objects // within same module (both private , // public definitons).  how  // several colleagues use them.  typedef struct obj_t {     uint8 val; }obj_t;  // how typically format aliases // both public , private definitions.  typedef struct {     uint8 val; }obj_t;  // ran one.  while makes sense  // how works, wasn't inherently better or // worse formats above. note different  // container names.  typedef struct obj_t {     uint8 val; }obj; 

they same, in define obj_t type alias structure.

the difference when define name of structure (e.g. struct obj ...) can also use struct obj mystructure; needed if want reference structure inside self (like when creating linked list example). if typedef before actual structure (like in first example) can of course use typedef'd name inside structure well.


Comments